whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

57 Visitors Online


 
...measure an elapsed time with a high-resolution performance counter?
Autor: Gstatter, Erhard
[ Print tip ]  

Tip Rating (9):  
     


{
  You want to measure the elapsed time in a repeat, while or a for -Loop
  to do some optimation ?

  Sie möchten eine Routine mit einer repeat, while oder for i :=...hinsichtlich der
  durchlaufenen Zeit messen, um z.B.Optimierungsaktivitäten durchzuführen.
}

// Global Variables, Globale Variablen:

  
t1, t2, Res: TLargeInteger;
  bOk: BOOL;

implementation

uses 
Windows, dialogs;

procedure StartTimer;
begin
  
bOK := QueryPerformanceFrequency(Res);
  if bOK then
    
QueryPerformanceCounter(t1);
end;

procedure StopTimer;
begin
  if 
bOK then
    
QueryPerformanceCounter(t2);
end;

procedure LoopRoutine;
var
  
iCounter: integer;
begin
  
StartTimer;
  // Put here some kind of loop: For, While or Repeat
  
for i := 0 to iCounter do...
  { WHILE....
   repeat...until}
  { After the Loop/
   Nach Abschluss der Schleifenroutine:}
    
if bOK then
      
QueryPerformanceCounter(t2);
end;

procedure StartSchleife;
begin
  
LoopRoutine;
  if bOK then
    
{$IFDEF VER80}
    // Show the elapsed time:
    
MessageDlg('Der Schleifendurchlauf dauerte: ' + Format('%g Sekunden.',
      [(t2.QuadPart - t1.Quadpart) / Res.QuadPart]));
  $Else {$IFDEF VER120}
  
MessageDlg('Der Schleifendurchlauf dauerte: ' + Format('%g Sekunden.',
    [(t2 - t1) / Res]));
  {$ENDIF}
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners