Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi WTF? ASM langsamer als Delphi? (https://www.delphipraxis.net/24815-wtf-asm-langsamer-als-delphi.html)

Xenon 26. Jun 2004 19:57


WTF? ASM langsamer als Delphi?
 
Hi,

einfach ein Memofeld namens mmAus erstellen, einen Button und diese prozedur dafür verwenden:

Laut Speedtest hab ich bei mir 1800 und 100 ms warum ist bitte der delphi code schneller als der ASM code?

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var f: array[1..8, 1..8] of byte;
    p: ^byte;
    i, j: cardinal;
    x, y: integer;
    s: string;
begin
  j := GetTickCount();
  for i:=1 to 1000000 do
  begin
  p := @f[1, 1];
  asm
    PUSH EAX
    PUSH EBX
    PUSH ECX
    PUSH EDX
    MOV ECX, 64
    MOV EBX, p
    ADD EBX, 63
    @@s1:
      PUSH ECX

      XOR EDX, EDX
      MOV EAX, ECX
      DEC EAX
      MOV ECX, 8
      DIV ECX
      INC EAX
      INC EDX
      CMP AL, DL
      JG @@mod
        MOV BYTE [EBX], AL
        JMP @@ende
      @@mod:
        MOV BYTE [EBX], DL
      @@ende:
      DEC EBX

      POP ECX
    LOOP @@s1
    POP EDX
    POP ECX
    POP EBX
    POP EAX
  end;
  end;
  j := GetTickCount-j;
  ShowMessage(IntToStr(j));
  j := GetTickCount();
  for i:=1 to 1000000 do
  begin
    for x:=1 to 8 do
      for y:=x to 8 do
      begin
        f[x, y] := x;
        f[y, x] := x;
      end;
  end;
  j := GetTickCount-j;
  ShowMessage(IntToStr(j));
  for j:=1 to 8 do
  begin
    s:='';
    for i:= 1 to 8 do
      s := s+format('%2d ', [f[i, j]]);
    mmAus.Lines.Add(s);
  end;
end;
Mfg Xenon

nailor 26. Jun 2004 20:26

Re: WTF? ASM langsamer als Delphi?
 
ohne jetzt groß ahnung von asm zu haben, vermute ich, dass der delphi-code einfach höher optimiert ist. entweder, weil du nicht 1:1 in asm übersetzt hast, sondern irgendwo eine abweichung zuungunsten deines asm codes drin hast, oder aber weil die delphi code optimization mal wieder ganze arbeit geleistet hat, und da irgendwas optimiert werden konnte.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz