Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.166 Beiträge
 
Delphi 12 Athens
 
#12

AW: Non-Visual-Komponente > Ereignisse im OI verknüpfen

  Alt 11. Nov 2010, 17:35
Diese Art von Events sind deutlich schneller und schlanker als das neue "reference to procedure" (auch bekannt als Closures).
Nja, soooo schlimm ist es nun auch nich.

Delphi-Quellcode:
program Project1;

uses
  Windows,
  SysUtils,
  Dialogs;

type
  TReference = reference to procedure;
  TMethod = procedure of object;
  TProcedure = procedure;

  TTest = class
    procedure Test;
  end;

procedure TTest.Test;
begin
end;

procedure Test;
begin
end;

var
  ref: TReference;
  method: TMethod;
  proc: TProcedure;
  t: TTest;
  c, c2, c3: Cardinal;
  i: Integer;

begin
  t := TTest.Create;

  c := GetTickCount;
  for i := 0 to 10000000 do
  begin
    ref := t.Test;
    ref;
    ref := nil;
  end;
  c := GetTickCount - c;

  c2 := GetTickCount;
  for i := 0 to 10000000 do
  begin
    method := t.Test;
    method;
    method := nil;
  end;
  c2 := GetTickCount - c2;

  c3 := GetTickCount;
  for i := 0 to 10000000 do
  begin
    proc := Test;
    proc;
    proc := nil;
  end;
  c3 := GetTickCount - c3;

  ShowMessage(Format('%d %d %d', [c, c2, c3]));
end.
Zitat:
~500 ~90 ~80
500 / 10000000 = 0,00005 ms pro Zuweisung+Aufruf
90 / 10000000 = 0,000009 ms pro Zuweisung+Aufruf

Und wenn nun noch irgendwas innerhalb der Prozedur und zwischen den Aufrufen passiert, dann verliert sich diese zusätzliche Zeit.
Schließlich wird Delphi auch nicht grade schneller, da fällt das "Bissl" nun och nicht mehr auf
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (11. Nov 2010 um 17:40 Uhr)
  Mit Zitat antworten Zitat