Something like this will do it?

procedure TForm1.Button1Click(Sender: TObject);
var
  start,stop1,stop2,freq:int64;
  i:integer;
begin
  screen.cursor:=crHourGlass; {show busy cursor}
  QueryPerformanceFrequency(freq); {Get frequency}
  QueryPerformanceCounter(start); {Get initial count}
  
  for i:=1 to 1000000 do;  {empty loop}
  QueryPerformanceCounter(stop1); {Get 1st end count}
  for i:=1 to 1000000 do application.processmessages; {do it loop}
  QueryPerformanceCounter(stop2);  {Get 2nd end count}
  screen.cursor:=crDefault;  {show normal cursor}
  If freq>0  {Display (loop2 count - loop1 count)/freq  to get time in 
microseconds}
  then showmessage('Time for a call to  processmessages is '  + 
inttostr(((stop2-stop1)-(stop1-start)) div freq)  +' microseconds')
  else showmessage('No hardware timer available');
end;



Anyway looks like on dual core, QueryPerformanceCounter has some problems:
http://www.virtualdub.org/blog/pivot/entry.php?id=106








Ken Adam wrote:
> How are you measuring time?
> You should be using QueryPerformanceCounter and QueryPerformanceFrequency to
> get precise timing.
>
> I get very consistent results from this (timing real-time digital map
> graphics code) without messing around with priorities, nor caring what else
> is running.
> (they give a resolution in microseconds, so doing enough calcs to take say 1
> second gives a precise answer).
> If you simply use elapsed time, then you will get a large variation, due to
> whatever else is happening, and the low resolution of the clock.
>
> If you haven't used these I can provide a sample.
>
> Regards,
> Ken
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
>
>   
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to