 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dennis Guest
|
Posted: Fri May 27, 2005 9:50 am Post subject: Fastcode MM B&V 0.40 |
|
|
Hi
I am building a very small release now.
It includes:
-Latest EWCMM
-Latest DKCMM
-Latest RecyclerMM
Best regards
Dennis
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Fri May 27, 2005 10:27 am Post subject: Re: Fastcode MM B&V 0.40 |
|
|
A suggestion for a new benchmark
Dennis
unit SortExtendedArrayBenchmark1Unit;
interface
uses Windows, BenchmarkClassUnit, Classes, Math;
type
TSortExtendedArrayThreads = class(TFastcodeMMBenchmark)
public
procedure RunBenchmark; override;
class function GetBenchmarkName: string; override;
class function GetBenchmarkDescription: string; override;
class function GetSpeedWeight: Double; override;
class function GetCategory: TBenchmarkCategory; override;
end;
implementation
uses SysUtils;
type
TSortExtendedArrayThread = class(TThread)
FBenchmark: TFastcodeMMBenchmark;
procedure Execute; override;
end;
TExtended = record
X : Extended;
Pad1, Pad2, Pad3, Pad4, Pad5, Pad6 : Byte;
end;
TExtendedArray = array[0..1000000] of TExtended;
PExtendedArray = ^TExtendedArray;
procedure TSortExtendedArrayThread.Execute;
var
ExtArray : PExtendedArray;
Size, I1, I2, I3, IndexMax, RunNo, LowIndex, HighIndex : Integer;
Temp, Max : Extended;
const
MAXRUNNO : Integer = 8;
MAXELEMENTVALUE : Integer = MAXINT;
MINSIZE : Integer = 100;
MAXSIZE : Integer = 10000;
begin
GetMem(ExtArray, MINSIZE * SizeOf(TExtended));
for RunNo := 1 to MAXRUNNO do
begin
Size := Random(MAXSIZE-MINSIZE) + MINSIZE;
//SetLength(ExtArray, Size);
ReallocMem(ExtArray, Size * SizeOf(TExtended));
//Fill array with random values
for I1 := 0 to Size-1 do
begin
ExtArray[I1].X := Random(MAXELEMENTVALUE);
end;
//Sort array just to create an acces pattern
//Using some weird DKC sort algorithm
LowIndex := 0;
HighIndex := Size-1;
repeat
if ExtArray[LowIndex].X > ExtArray[HighIndex].X then
begin
//Swap
Temp := ExtArray[LowIndex].X;
ExtArray[LowIndex].X := ExtArray[HighIndex].X;
ExtArray[HighIndex].X := Temp;
end;
Inc(LowIndex);
Dec(HighIndex);
until(LowIndex >= HighIndex);
for I2 := Size-1 downto 1 do
begin
//Find biggest element in unsorted part of array
Max := ExtArray[I2].X;
IndexMax := I2;
for I3 := I2-1 downto 0 do
begin
if ExtArray[I3].X > Max then
begin
Max := ExtArray[I3].X;
IndexMax := I3;
end;
end;
//Swap current element with biggest remaining element
Temp := ExtArray[I2].X;
ExtArray[I2].X := ExtArray[IndexMax].X;
ExtArray[IndexMax].X := Temp;
end;
end;
//Free array
FreeMem(ExtArray);
FBenchmark.UpdateUsageStatistics;
end;
class function TSortExtendedArrayThreads.GetBenchmarkDescription: string;
begin
Result := 'A benchmark that measures read and write speed to an array of
Extendeds. '
+ 'The Extended type is padded to be 16 byte. '
+ 'Bonus is given for 16 byte alignment of array '
+ 'Will also reveil cache set associativity related issues. '
+ 'Access pattern is created by X sorting array of random values.
'
+ 'Measures memory usage after all blocks have been freed. '
+ 'Benchmark submitted by Dennis Kjaer Christensen.';
end;
class function TSortExtendedArrayThreads.GetBenchmarkName: string;
begin
Result := 'SortExtendedArrayBenchmark';
end;
class function TSortExtendedArrayThreads.GetCategory: TBenchmarkCategory;
begin
Result := bmMemoryAccessSpeed;
end;
class function TSortExtendedArrayThreads.GetSpeedWeight: Double;
begin
Result := 0.75;
end;
procedure TSortExtendedArrayThreads.RunBenchmark;
var
SortExtendedArrayThread1, SortExtendedArrayThread2 :
TSortExtendedArrayThread;
SortExtendedArrayThread3, SortExtendedArrayThread4 :
TSortExtendedArrayThread;
begin
inherited;
SortExtendedArrayThread1 := TSortExtendedArrayThread.Create(True);
SortExtendedArrayThread2 := TSortExtendedArrayThread.Create(True);
SortExtendedArrayThread3 := TSortExtendedArrayThread.Create(True);
SortExtendedArrayThread4 := TSortExtendedArrayThread.Create(True);
SortExtendedArrayThread1.FreeOnTerminate := False;
SortExtendedArrayThread2.FreeOnTerminate := False;
SortExtendedArrayThread3.FreeOnTerminate := False;
SortExtendedArrayThread4.FreeOnTerminate := False;
SortExtendedArrayThread1.Priority := tpLower;
SortExtendedArrayThread2.Priority := tpNormal;
SortExtendedArrayThread3.Priority := tpHigher;
SortExtendedArrayThread4.Priority := tpHighest;
SortExtendedArrayThread1.FBenchmark := Self;
SortExtendedArrayThread2.FBenchmark := Self;
SortExtendedArrayThread3.FBenchmark := Self;
SortExtendedArrayThread4.FBenchmark := Self;
SortExtendedArrayThread1.Resume;
SortExtendedArrayThread2.Resume;
SortExtendedArrayThread3.Resume;
SortExtendedArrayThread4.Resume;
SortExtendedArrayThread1.WaitFor;
SortExtendedArrayThread2.WaitFor;
SortExtendedArrayThread3.WaitFor;
SortExtendedArrayThread4.WaitFor;
SortExtendedArrayThread1.Free;
SortExtendedArrayThread2.Free;
SortExtendedArrayThread3.Free;
SortExtendedArrayThread4.Free;
end;
end.
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Fri May 27, 2005 10:27 am Post subject: Re: Fastcode MM B&V 0.40 |
|
|
Hi
How do I make a watch on the array - ExtArray : PExtendedArray; ?
Dennis
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Fri May 27, 2005 11:15 am Post subject: Re: Fastcode MM B&V 0.40 |
|
|
| Quote: | A suggestion for a new benchmark
|
Wouldn't it make more sense to use an O(n log n) algorithm? ISTM in
practice O(n^2) sorting algorithms are rarely used, especially when
speed is an issue.
I think the access pattern for such an algorithm is quite different.
Perhaps just using TList.Sort (which uses QuickSort) is a good way to
get the most common access pattern.
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Fri May 27, 2005 12:57 pm Post subject: Re: Fastcode MM B&V 0.40 |
|
|
Hi Avatar
| Quote: | Wouldn't it make more sense to use an O(n log n) algorithm? ISTM in
practice O(n^2) sorting algorithms are rarely used, especially when
speed is an issue.
|
Perhaps
| Quote: | I think the access pattern for such an algorithm is quite different.
|
Yes.
| Quote: | Perhaps just using TList.Sort (which uses QuickSort) is a good way to
get the most common access pattern.
|
Very good idea. Let us make yet another benchmark. Do you volunteer to make
it?
Regards
Dennis
|
|
| Back to top |
|
 |
Avatar Zondertau Guest
|
Posted: Fri May 27, 2005 2:31 pm Post subject: Re: Fastcode MM B&V 0.40 |
|
|
| Quote: | Perhaps just using TList.Sort (which uses QuickSort) is a good way
to get the most common access pattern.
Very good idea. Let us make yet another benchmark. Do you volunteer
to make it?
|
Below follows a modification of your benchmark which uses TList.Sort. I
only included the Execute method (and a newly added procedure
SortCompareExtended), the rest is the same. I didn't test it.
If you want it to put more load on the MM then you could modify the
code the just insert items in the list, not setting it's size in
advance.
function SortCompareExtended(Item1, Item2: Pointer): Integer;
var
Diff: Extended;
begin
Diff := PExtended(Item1)^ - PExtended(Item2)^;
if Diff < 0 then
Result := -1
else
if Diff > 0 then
Result := 1
else
Result := 0;
end;
procedure TSortExtendedArrayThread.Execute;
var
ExtArray: PExtendedArray;
I, RunNo, Size: Integer;
List: TList;
const
MAXRUNNO : Integer = 8;
MAXELEMENTVALUE : Integer = MAXINT;
MINSIZE : Integer = 100;
MAXSIZE : Integer = 10000;
begin
GetMem(ExtArray, MINSIZE * SizeOf(TExtended));
try
for RunNo := 1 to MAXRUNNO do
begin
Size := Random(MAXSIZE-MINSIZE) + MINSIZE;
ReallocMem(ExtArray, Size * SizeOf(TExtended));
List := TList.Create;
try
List.Count := Size;
for I := 0 to Size-1 do
begin
ExtArray[I].X := Random(MAXELEMENTVALUE);
List[I] := @ExtArray[I].X;
end;
List.Sort(SortCompareExtended);
finally
List.Free;
end;
end;
finally
FreeMem(ExtArray);
end;
FBenchmark.UpdateUsageStatistics;
end;
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Fri May 27, 2005 3:19 pm Post subject: Re: Fastcode MM B&V 0.40 |
|
|
| Quote: | -Latest RecyclerMM
|
I guess it'll be no longer necessary to have this one,
BucketMem & FastMM have the overall approach well covered
now, and since I won't have much time to work on it,
I'll rather focus on other peripheral aspects (like finally
getting a clean memory transfer test app, for usage in MM
reallocs, or wrapping/cleaning up the MMF logic for large
blocks, as I suspect the multi-CPU failures in latest
RecyclerMMs come from it).
So I'll let Robert & Pierre (& others) squeeze the last
percentage points out of the paged/segregated allocator ;)
Eric
|
|
| Back to top |
|
 |
Dennis Guest
|
|
| Back to top |
|
 |
Dennis Guest
|
Posted: Tue May 31, 2005 2:56 pm Post subject: Re: Fastcode MM B&V 0.40 |
|
|
Hi Avatar
| Quote: | Below follows a modification of your benchmark which uses TList.Sort. I
only included the Execute method (and a newly added procedure
SortCompareExtended), the rest is the same. I didn't test it.
|
Can you finish it and test it?
Regards
Dennis
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|