//Helping Function for "GetCPUSpeed"
function ActivateTimer: Int64;
asm
push eax
push edx
db 0fh
db 31h
mov [esp], eax
mov [esp+4], edx
pop eax
pop edx
end;
// From "CPUID for Delphi" by Ural Gunaydin
function GetCpuSpeed(msTime: DWORD): Double;
var
llStart, llStop: Int64;
dwStart: DWORD;
timecaps: TTimeCaps;
bf1, bf2, minErr, tErr,
ratio, bestRatio, bestBf: Double;
begin
result:= 0.0;
if (timeGetDevCaps(@timecaps, sizeof(TTimeCaps)) <> TIMERR_NOERROR)
then
Exit;
timeBeginPeriod(timecaps.wPeriodMax);
dwStart:= timeGetTime;
llStart:= ActivateTimer;
while ((timeGetTime() - dwStart) < msTime)
do
begin
//
end;
llStop:= ActivateTimer;
timeEndPeriod(timecaps.wPeriodMax);
result:= (llStop - llStart) / msTime;
bf1:= 1000*50.00000;
bf2:= 1000*66.66666;
minErr:= result;
ratio:= Round(result / bf1);
bestRatio:= ratio;
bestBf:= bf1;
tErr:= (ratio * bf1) - result;
if (tErr < minErr)
then
begin
minErr:= tErr;
bestRatio:= ratio;
bestBf:= bf1;
end;
ratio:= ratio-1;
tErr:= result - (ratio * bf1);
if (tErr < minErr)
then
begin
minErr:= tErr;
bestRatio:= ratio;
bestBf:= bf1;
end;
ratio:= Round(result / bf2);
tErr:= (ratio * bf2) - result;
if (tErr < minErr)
then
begin
minErr:= tErr;
bestRatio:= ratio;
bestBf:= bf2;
end;
ratio:= ratio-1;
tErr:= result - (ratio * bf2);
if (tErr < minErr)
then
begin
bestRatio:= ratio;
bestBf:= bf2;
end;
result:= bestRatio * bestBf;
//CpuInfo.CPUFreq:= result;
end;