Re: filling big array of double



Eric Grange wrote:
 > It is 2 times slower

Hmmm... than what? ;)

:)

Got me curious, and I tested the pascal code you posted in your reply to Aleksandr (after adapting it to double, the code you posted was for Integers), on AthlonXP it came out 1.5x faster than your pascal version for large arrays (and approx 2x for small arrays).

Eric

I'm testing on a P4 3Ghz and this is my code:

procedure FillDouble(var Dest; Count: integer; Value: double); register;
{$IFNDEF USEASM} // 2687 ms
var
  i: integer;
  p: PDouble;
begin
  p := @dest;
  for i := 1 to count do
  begin
    p^ := Value;
    inc(integer(p), 8);
  end;
end;
{$ELSE} // 5656 ms
asm
   test  edx, edx
   jz    @@End
   fld   qword ptr [ebp+8]
@@Loop:
   fst   qword ptr [eax]
   lea   eax, eax+8
   dec   edx
   jnz   @@Loop
   ffree st(0)
@@End:
end;
{$ENDIF}

procedure TForm1.Button2Click(Sender: TObject);
var
  c: cardinal;
  i: integer;
  buffer: array[1..1000] of double;
begin
  c := GetTickCount;
  for i := 1 to 1000000 do
    FillDouble(buffer, length(buffer), 1.1);
  memo1.Lines.Add(inttostr(GetTickCount - c));
end;

.


Quantcast