alecash
August 6th, 2001, 07:58 AM
Is there a function in Visual Basic to get the clock frequency of the PC's processor ?
Any help appreciated.
Any help appreciated.
|
Click to See Complete Forum and Search --> : Getting frequency of processor alecash August 6th, 2001, 07:58 AM Is there a function in Visual Basic to get the clock frequency of the PC's processor ? Any help appreciated. Cimperiali August 6th, 2001, 08:03 AM http://codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=58062&page=&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 alecash August 6th, 2001, 08:14 AM Sorry but this doesn't answer to my question. I'm not interested in getting the occupation of the CPU. Kdev August 6th, 2001, 08:24 AM Have a look at: http://www.planet-source-code.com/xq/ASP/txtCodeId.22274/lngWId.1/qx/vb/scripts/ShowCode.htm -K Clearcode August 7th, 2001, 04:19 AM 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. Cimperiali August 8th, 2001, 06:51 AM 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 Clearcode August 8th, 2001, 11:44 AM 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. Cimperiali August 9th, 2001, 02:14 AM 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: KPDTeam@Allapi.net 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 codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |