Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve Processor Speed & Info?

Status
Not open for further replies.

mbasic

Programmer
May 18, 2002
13
0
0
GB



Hi Everyone.

Great Forum.
I wonder if someone could please help.
I'm trying to write a program which will return the speed of the system's processor, but without luck.

I've tried using the various Windows API functions contained within "kernel32.dll", an the reading the registry (this works, bu only under NT/2000/XP, not 9*), I'm currently trying using the system's high-performance timer, but again without any luck.

Below is my code.
Please can you tell me if I'm using the functions correctly, as currently they return the same value on every computer I've tested it on?

Is there any other way (idealy simpler) of doing this?
What about Intel's CpuID instruction set? Is the source code for this freely usable in distributed programs?
How do I adapt it to return CPU speed in QBasic.

Ideally I would like some simple way (jus a few lines of code if possible), that simply returns a 'reasonably accurtae' measure of the processor speed.

Any help would be very much appreciated.
Many Thanks.
Best Wishes,


MBasic
[pipe]


THE CODE :
'====================================================

Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
' CUSTOM DATA TYPE TO HANDLE LARGE INTEGERS



Declare Function QueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As LARGE_INTEGER) As Long
Declare Function QueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As LARGE_INTEGER) As Long
' I DECLARE THE API FUNCTIONS HERE

dim constFreq as LARGE_INTEGER
dim time1 as LARGE_INTEGER
dim time2 as LARGE_INTEGER
dim outTime as Double
dim timeDif as Long
' VARIABLE DECLERATIONS



QueryPerformanceCounter(lpPerformanceCount)
lpPerformanceCount = time1
' QUERY OF PERFORMANCE COUNTER BEFORE THE EQUATION

' MY CALCULATIONS TO TIME GOES HERE

QueryPerformanceCounter(lpPerformanceCount)
lpPerformanceCount = time2
' QUERY OF PERFORMANCE COUNTER AFTER THE EQUATION

QueryPerformanceFrequency(lpFrequency)
lpFrequency = constFreq
' QUERY THE PERFORMANCE FREQUENCY (CONSTANT - CPU SPECIFIC?)



timeDif = time2-time1
outTime = timeFif/constFreq
' CALCULATE PERFORMANCE RATIO

' I OUTPUT THE RESULTS HERE

'=======================================================
 
Actually, you need to post this to the correct forum ^_^ This is the QuickBASIC forum, not Visual Basic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top