Alexander Klenin пишет:

Ok, I re-tested with 2*10^6 Find's. Then AnsiString variants wins even
for length 5:

ShortString: 0.547 s
AnsiString: 0.437 s

Running the test, I get quite opposite results:

0.750 sec
0.766 sec
short add:  1.829 sec
short find: 0.781 sec
ansi add:   1.750 sec
ansi find:  1.406 sec

The only modifications I made to the test is added printing separate numbers for 'find' and 'add', and printing labels. Modified test is attached.

Although theoretically Find() should show no difference at all, because it performs the same operations on the same data. IOW, the difference seen is caused either by CPU cache effects, or by bugs in testing.

No difference between the first two numbers (IntToStr for ShortString and AnsiString) is also quite suspicious...

Regards,
Sergei
{$mode objfpc}{$h+}
uses
  contnrs, uhla, sysutils;

var
  t: Double;

procedure Benchmark;
begin
  Writeln((Now - t) * 24 * 60 * 60:0:3, ' sec');
end;

var
  hl: TFPHashList;
  hla: TFPHashListA;
  i: Integer;
  a: ShortString;
  b: AnsiString;
begin
Writeln(SizeOf(b));
  t := Now;
  for i := 1 to 3000000 do
    a := IntToStr(i);
  Benchmark;
  t := Now;
  for i := 1 to 3000000 do
    b := IntToStr(i);
  Benchmark;
  
  hl := TFPHashList.Create;
  for i := 1 to 2000000 do begin
    a := IntToStr(i);
    hl.Add(a, Pointer(i));
  end;
  write('short add:  ');
  Benchmark;
  t := Now;
  for i := 1 to 2000000 do begin
    a := IntToStr(i);
    hl.Find(a);
  end;
  write('short find: ');
  Benchmark;

  hla := TFPHashListA.Create;
  for i := 1 to 2000000 do begin
    b := IntToStr(i);
    hla.Add(b, Pointer(i));
  end;
  write('ansi add:   ');
  Benchmark;
  t := Now;
  for i := 1 to 2000000 do begin
    b := IntToStr(i);
    hla.Find(b);
  end;
  write('ansi find:  ');
  Benchmark;

end.
_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to