January 26, 2023, 09:40:40 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Approximating CPU speed

Started by Ionic Wind Support Team, July 22, 2006, 05:16:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

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 ;)

Ionic Wind Support Team

kryton9


John S

compile this one in a console!
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

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 ;)
Ionic Wind Support Team

Barney

2210 MHz here which is pretty correct as theoretically it should be 2200 MHz. (AMD X2 4400+)

Barney

Rock Ridge Farm (Larry)


Haim

1694 Mhz on my IBM laptop. rated at 1700 Mhz.
Pretty good approximation.
Haim

Doc

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-

Ionic Wind Support Team

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();

Ionic Wind Support Team

John Syl.

3591 Mhz

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

regards
John
Intel 3.6 p4 ht, XP home,2 gb mem, 400 gb hd 20gb raid 0, Nvidia 6600le.
AMD k6-2 500, 40gb.

Started on PDP11 Assembler, BASIC, GWBASIC, 6502, Z80, 80x86, Java, Pascal, C, C++, 
IBasic (std & pro), Aurora, EBasic.  (Master of none, but it's been fun!)

LarryMc

QuoteI've lost  9 Mhz  thats equivalent to an 8086 and Z80!!!   

oooooooooh... must hace been a TURBO XT! ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library