Answer the question
In order to leave comments, you need to log in
How fast is a piece of code executed in Delphi?
Hello,
I need to find out how quickly this or that piece of code is executed in Delphi. For example, to measure the speed of execution of certain procedures or functions. I looked at examples on the Internet, but using GetTickCount it’s not very accurate, and sometimes it doesn’t give a result at all. Please help.
Tried to do like this:
function GetCPUTick: Int64;
asm
DB $0F,$31
end;
function CalibrateCPU: int64;
var
t: cardinal;
begin
t := GetTickCount;
while t=GetTickCount do;
Result := GetCPUTick;
while GetTickCount<(t+400) do;
Result := GetCPUTick - result;
CPUClock := 2.5e-6*Result;
end;
function TicksToStr(const Value: int64): string;
begin
Result := FloatToStrF(Value/CPUClock,fffixed,10,2)+ ' мс';
end;
_______________________________________________________________
CalibrateCPU;
ticks := GetCPUTick;
bubblesort(arr100,0,100);
ticks := GetCPUTick - ticks;
Answer the question
In order to leave comments, you need to log in
I used procedures which are already described in :
QueryPerformanceFrequency - an amount of cycles for millisecond
QueryPerformanceCounter - an amount of cycles
Your example:
var
tc,tc2,tcins:int64;
QueryPerformanceFrequency(tcins);
QueryPerformanceCounter(tc);
bubblesort(arr100,0,100);
QueryPerformanceCounter(tc2);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question