nielsie95
2008-08-11 14:03:40
Hey,
Ever wanted to really time your functions in scar? With GetTickCount you have a 16ms margin. This - make sure API calls are enabled - is way more precise:
Cheers,
Nielsie95
Ever wanted to really time your functions in scar? With GetTickCount you have a 16ms margin. This - make sure API calls are enabled - is way more precise:
program New;
function QueryPerformanceFrequency(out Frequency: Int64): LongBool; external 'QueryPerformanceFrequency@kernel32.dll stdcall';
function QueryPerformanceCounter(out Counter: Int64): LongBool; external 'QueryPerformanceCounter@kernel32.dll stdcall';
procedure MarkTime(var Time: Int64);
var
Freq: Int64;
begin
if QueryPerformanceFrequency(Freq) then
QueryPerformanceCounter(Time)
else
Time := GetTickCount;
end;
function TimeFromMark(Mark: Int64): Double;
var
Freq, Now: Int64;
begin
if QueryPerformanceFrequency(Freq) then
begin
QueryPerformanceCounter(Now);
Result := ((Now - Mark) / Freq) * 1000;
end
else
Result := (GetTickCount - Mark);
end;
var
Time: Int64;
begin
MarkTime(Time);
WriteLn('Straight from MarkTime took ' + FloatToStr(TimeFromMark(Time)) + ' ms.');
Wait(10);
WriteLn('After another Wait(10) we are ' + FloatToStr(TimeFromMark(Time)) + ' ms away from the mark.');
end.
Cheers,
Nielsie95