|
-
August 6th, 2001, 07:58 AM
#1
Getting frequency of processor
Is there a function in Visual Basic to get the clock frequency of the PC's processor ?
Any help appreciated.
-
August 6th, 2001, 08:03 AM
#2
Re: Getting frequency of processor
http://codeguru.com/cgi-bin/bbs/wt/s...age=&view=&sb=
Clearcode docet
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 6th, 2001, 08:14 AM
#3
Re: Getting frequency of processor
Sorry but this doesn't answer to my question. I'm not interested in getting the occupation of the CPU.
-
August 6th, 2001, 08:24 AM
#4
Re: Getting frequency of processor
-
August 7th, 2001, 04:19 AM
#5
Re: Getting frequency of processor
Without 3rd party dlls solution:
private Declare Function QueryPerformanceFrequency Lib "kernel32.dll" (lpFrequency as Long) as Long
public property get PerformanceFrequency() as Long
Dim lRet as Long
Dim lFrequency as Long
lRet = QueryPerformanceFrequency(lFrequency)
If Err.LastDllError <> 0 then
MsgBox "error getting processor frequency"
else
PerformanceFrequency = lFrequency
End If
End property
Hope this helps,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
August 8th, 2001, 06:51 AM
#6
Re: Getting frequency of processor
Only a pity I am out of votes...
Have a nice day, man.
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 8th, 2001, 11:44 AM
#7
Re: Getting frequency of processor
Actually there's a bit more work needed, as I'm passing a VB Long but the API call should return a LARGE_INTEGER so the number might not be right.
Does the value you get tally with your CPU expectation?
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
-
August 9th, 2001, 02:14 AM
#8
Re: Getting frequency of processor
private Type LARGE_INTEGER
LowPart as Long
HighPart as Long
End Type
private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount as LARGE_INTEGER) as Long
private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency as LARGE_INTEGER) as Long
private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim T as Long, liFrequency as LARGE_INTEGER, liStart as LARGE_INTEGER, liStop as LARGE_INTEGER
Dim cuFrequency as Currency, cuStart as Currency, cuStop as Currency
'Retrieve the frequency of the performance counter
If QueryPerformanceFrequency(liFrequency) = 0 then
MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
else
'convert the large integer to currency
cuFrequency = LargeIntToCurrency(liFrequency)
'retrieve tick count
QueryPerformanceCounter liStart
'do something
for T = 0 to 100000
DoEvents
next T
'retrieve tick count
QueryPerformanceCounter liStop
'convert large integers to currency's
cuStart = LargeIntToCurrency(liStart)
cuStop = LargeIntToCurrency(liStop)
'calculate how many seconds passed, and show the result
MsgBox "time: " + CStr((cuStop - cuStart) / cuFrequency) + " seconds"
End If
End Sub
private Function LargeIntToCurrency(liInput as LARGE_INTEGER) as Currency
'copy 8 bytes from the large integer to an ampty currency
CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
'adjust it
LargeIntToCurrency = LargeIntToCurrency * 10000
End Function
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|