CPU SPEED

Just starting out? Need help? Post your questions and find answers here.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Tronds = 1862
NoahPhense = 3724
Akj = 2036
Netmaestro = 1862

So apart from Akj they all seem ok on intels.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Please keep in mind, that I'm working with a laptop processor. So, when
I put the laptop in Laptop/Portable mode, the processor drops to a
Dynamic 50%. Meaning that for all normal applications, a 2.16ghz dual
core processor will drop to 1.08ghz, meaning .54 ghz each core. (540).

Some other CPU apps on the net can see this. Even the windows built-in
perfmon.msc can see this. Even some of the code already posted here
has been able to detect this, in debug mode in PB. But after creating an
exe, it flys back to full power.

?

Code: Select all

Declare AppendFile(FileName.s, String.s)

Global Fn = 99

Enumeration 1
  #Window_frm_main
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue

Enumeration 1
  ;Window_frm_main
  #Gadget_frm_main_txt_main
EndEnumeration

#GadgetIndex=#PB_Compiler_EnumerationValue

Procedure.l Window_frm_main()
  If OpenWindow(#Window_frm_main,212,145,192,45,"CPU Speed Recorder",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_frm_main))
      TextGadget(#Gadget_frm_main_txt_main,10,10,130,25,"DATA")
      SetGadgetFont(#Gadget_frm_main_txt_main,LoadFont(#Gadget_frm_main_txt_main,"@Arial Unicode MS",14,0))
      HideWindow(#Window_frm_main,0)
      ProcedureReturn WindowID(#Window_frm_main)
    EndIf
  EndIf
EndProcedure

Procedure.q GetCycleCount() 
  !rdtsc 
  ProcedureReturn 
EndProcedure 

Procedure CPUSPEED() 
  Protected A.q 
  Protected B.q 
  A = GetCycleCount() 
  Sleep_(100) 
  B = GetCycleCount() 
  ProcedureReturn (B-A) / 100000 
EndProcedure 

Procedure AppendFile(FileName.s, String.s) 
  If OpenFile(Fn, FileName) 
    FileSeek(Fn, Lof(Fn)) 
    WriteStringN(Fn, String) 
    CloseFile(Fn) 
  EndIf 
EndProcedure 

Procedure Tick() 
  dData.s = FormatDate("%hh:%ii:%ss", Date())
  cData.s = Str(CPUSPEED())
  finalData.s = dData + " - " + cData
  ; AppendFile("cpu.log", finalData)
  Debug finalData
  SetGadgetText(#Gadget_frm_main_txt_main, cData)
EndProcedure 

If Window_frm_main()

  quitfrm_main=0
  SetGadgetText(#Gadget_frm_main_txt_main, "**")
  SetTimer_(WindowID(#Window_frm_main), 1, 1000, @Tick())
  
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_frm_main
          quitfrm_main=1
        EndIf

      Case #PB_Event_Gadget
        Select GadgetID
        EndSelect

    EndSelect
  Until quitfrm_main
  KillTimer_(WindowID(#Window_frm_main), 1)
  CloseWindow(#Window_frm_main)
EndIf

End
- np
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

netmaestro it is a wonder your code is reliable at all.
That is the high performance crystal timing frequency and not related to MHz at all.
http://msdn.microsoft.com/library/defau ... ounter.asp

On my AMD the returned value of QueryPerformanceCounter Function is 3579545 and thus result in 3 after that divide.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Rescator, you misread the function call. You reference QueryPerformanceCounter, where my code uses QueryPerformanceFrequency:
MSDN wrote:QueryPerformanceFrequency Function

--------------------------------------------------------------------------------

The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.

Syntax

BOOL QueryPerformanceFrequency( LARGE_INTEGER *lpFrequency
);
Parameters

lpFrequency
[out] Pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.
which seems like it should work, and it does on all my machines. I don't know why it doesn't work on some machines, but I guess it's not too reliable.
BERESHEIT
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

netmaestro wrote:Rescator, you misread the function call. You reference QueryPerformanceCounter, where my code uses QueryPerformanceFrequency

which seems like it should work, and it does on all my machines. I don't know why it doesn't work on some machines, but I guess it's not too reliable.
QueryPerformanceFrequency is used to get the resolution of the high-resolution performance counter,
the returned value is then used with QueryPerformanceCounter result to calculate the time passed.

QueryPerformanceFrequency has nothing to do with the cpu or MHz of the cpu,
it is related to the highest resolution performance counter,
in your case the pentium systems use the cpu cycle counter,
in the case of AMD cpu's most use either a cpu speed independent crystal/counter, or a external clock (bios)
and in the case of scientific equipment it could even be a atomic clock/timer device.

PS! Unless I'm mistaken, cpu cycles themselves are unreliable for MHz
(millions of instructions per second) meassurement as some cpu's are
able to execute multiple instructions in a single cycle.
Which is why benchmark tools use MIPS and FLOPS rather
than MHz in it's comparison tests.

It would be fun however to do a NOPS benchmark routine:P
Sorry, couldn't resist a little asm joke there, hope some of you got it :P
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I think the most reliable (and fast) way is to look in the registry. That'll tell you what Windows has been able to determine as well as how many cores you have. The idea I posted is no good at all. Those methods based on RDTSC are OK for single-core processors but they return unreliable results on multi-core systems. For example, my 2.0 ghz AMD 3800 X2 is reporting 2200 mhz, which isn't right. I have 2 cores each going 2000 mhz, so 2200 isn't a useful number.
BERESHEIT
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

FYI
In Windows ME, the Windows registry does not store CPU speed anywhere within
HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0
even though this key exists.
Anthony Jordan
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Found out that you get more reliable results when you increase the time:

Code: Select all

Procedure CPUSPEED()
  Protected A.q
  Protected B.q
  A = GetCycleCount()
  Sleep_(1500)
  B = GetCycleCount()
  ProcedureReturn (B-A) / 1500000
EndProcedure
at least on my machines.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Ok, one more time. The registry is great for seeing what your "max"
cpu speed is. But useless to determine what your process is currently
running at.

A laptop in Portable/Laptop does NOT run at full speed. It runs about
half speed. In Home/Office Desk, it runs in full cpu mode.

While a laptop is in Portable/Laptop (power setting), it can run full, but
only when the demand is there.

i.e. If I'm doing Word, Excel, etc.. system runs about 50% of total mhz.
The second I launch a game, the processor will run full.

- np
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Post by Hi-Toro »

Dunno if Windows 2000/above-only code is any use to you, but if it is, take a look at this and see if it works for you:

http://www.purebasic.fr/english/viewtopic.php?t=25310
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Hi-Toro wrote:Dunno if Windows 2000/above-only code is any use to you, but if it is, take a look at this and see if it works for you:

http://www.purebasic.fr/english/viewtopic.php?t=25310
That's freakin perfect.

Thanks HT!

- np
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Post by Hi-Toro »

Glad it worked!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
Post Reply