Mit folgendem Code kannst Du herausfinden, was Dein BS (WIN XP, WIN732, WIN764) auf der vorhandenen Hardware (Solo,Duo) bei Sleep() an Zeit "verbraucht":
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var a, b, c: Int64; r: real; i: Integer;
begin
For i:=0 to 20 do
BEGIN
QueryPerformanceFrequency(a);
QueryPerformanceCounter(b);
Sleep(i);
QueryPerformanceCounter(c);
r:= (c - b) * 1000 / a;
Memo1.lines.add('Sleep('+IntToStr(i)+') = '+ FloatToStrF(r, ffFixed, 12, 5)+' msec');
Application.ProcessMessages;
END;
end;
Eine bessere SLEEP-Funktion:
Delphi-Quellcode:
procedure DelayQPC(t: cardinal);
var a, b: Int64;
Begin
QueryPerformanceFrequency(b);
QueryPerformanceCounter(a);
b := a + (b * t) div 1000;
While a < b do QueryPerformanceCounter(a);
end;
Aufruf z.B:
DelayQPC(1000);
Test mit DelayQPC:
Delphi-Quellcode:
procedure DelayQPC(t: cardinal);
var a, b: Int64;
Begin
QueryPerformanceFrequency(b);
QueryPerformanceCounter(a);
b := a + (b * t) div 1000; //10000 für 0.1 msec
While a < b do QueryPerformanceCounter(a);
end;
procedure TForm1.Button1Click(Sender: TObject);
var a, b, c: Int64; r: real; i: Integer;
begin
For i:=1 to 20 do
BEGIN
QueryPerformanceFrequency(a);
QueryPerformanceCounter(b);
DelayQPC(i*100);
QueryPerformanceCounter(c);
r:= (c - b) * 1000 / a;
Memo1.lines.add('Sleep('+IntToStr(i*100)+') = '+ FloatToStrF(r, ffFixed, 12, 5)+' msec');
Application.ProcessMessages;
END;
end;