While I was playing with timers I came up with this:
import int QueryPerformanceFrequency(int64 *lpFrequency);
import int QueryPerformanceCounter(int64 *lpPerformanceCount);
global sub main()
{
int64 freq;
int64 countstart,countend;
int64 startcpu,endcpu;
QueryPerformanceFrequency(freq);
QueryPerformanceCounter(countstart);
countend = countstart;
startcpu = readts();
while(countend - countstart) < freq
{
QueryPerformanceCounter(countend);
}
endcpu = readts();
print((endcpu-startcpu)/1000000,"Mhz");
while GetKey() = "";
}
sub readts(),int64
{
int64 ret;
#asm
rdtsc
lea esi,[ebp]
mov [esi-8],eax
mov [esi-4],edx
#endasm
return ret;
}
Which is a method of approximating your current CPU speed. However it will probably only work on single core machines and may give silly results. You were warned ;)
Cool idea and example.
compile this one in a console!
Yes it has a print statement so it needs a console.
Post your results here too just to see how it works on other machines ;)
2210 MHz here which is pretty correct as theoretically it should be 2200 MHz. (AMD X2 4400+)
Barney
My HP laptop - 1808 mzh
1694 Mhz on my IBM laptop. rated at 1700 Mhz.
Pretty good approximation.
Haim
2087 Mhz using a 64 Bit AMD processor rated at 2000 Mhz
Looks to be pretty darned accurate on a wide variety of CPU's. 8)
-Doc-
That's cool.
You can use the readts function to time and tweak code speed too.
start = readts();
...some long code your trying to make faster
end = readts();
3591 Mhz
P4 660 HT 3.6Ghz .... I've lost 9 Mhz thats equivalent to an 8086 and Z80!!! ;D
regards
John
QuoteI've lost 9 Mhz thats equivalent to an 8086 and Z80!!!
oooooooooh... must hace been a TURBO XT! ;D