IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: Ionic Wind Support Team on July 22, 2006, 05:16:43 PM

Title: Approximating CPU speed
Post by: Ionic Wind Support Team on July 22, 2006, 05:16:43 PM
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 ;)

Title: Re: Approximating CPU speed
Post by: kryton9 on July 22, 2006, 09:20:32 PM
Cool idea and example.
Title: Re: Approximating CPU speed
Post by: John S on July 22, 2006, 11:50:29 PM
compile this one in a console!
Title: Re: Approximating CPU speed
Post by: Ionic Wind Support Team on July 22, 2006, 11:53:24 PM
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 ;)
Title: Re: Approximating CPU speed
Post by: Barney on July 23, 2006, 05:33:18 AM
2210 MHz here which is pretty correct as theoretically it should be 2200 MHz. (AMD X2 4400+)

Barney
Title: Re: Approximating CPU speed
Post by: Rock Ridge Farm (Larry) on July 23, 2006, 05:40:15 AM
My HP laptop - 1808 mzh
Title: Re: Approximating CPU speed
Post by: Haim on July 23, 2006, 05:56:19 AM
1694 Mhz on my IBM laptop. rated at 1700 Mhz.
Pretty good approximation.
Haim
Title: Re: Approximating CPU speed
Post by: Doc on July 23, 2006, 07:51:52 AM
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-
Title: Re: Approximating CPU speed
Post by: Ionic Wind Support Team on July 23, 2006, 07:57:17 AM
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();

Title: Re: Approximating CPU speed
Post by: John Syl. on July 23, 2006, 10:49:06 AM
3591 Mhz

P4 660 HT 3.6Ghz ....  I've lost  9 Mhz  thats equivalent to an 8086 and Z80!!!   ;D

regards
John
Title: Re: Approximating CPU speed
Post by: LarryMc on July 23, 2006, 01:00:05 PM
QuoteI've lost  9 Mhz  thats equivalent to an 8086 and Z80!!!   

oooooooooh... must hace been a TURBO XT! ;D