Solved

How do I get CPU Clock Speed

Posted on 1997-05-16
5
351 Views
Last Modified: 2010-04-04
How do I get CPU Clock Speed (200 MHz, 166 MHz, etc.) within
my Delphi 2.0 program.  I have tried about 10 different "System Info" components and none return this information.
I cannot find it in the registry either.  I really need a way to get this on all Windows platforms, but definitely in Win95 and WinNT.  I'm brand new to Delphi, so this is probably easy for some of you.  Please help a new guy.  Thanks in advance for your time.
0
Comment
Question by:Rik
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336359
Didn't I answer this on news???

Anyway, this works for Win95 and NT if the hardware supports it.


function CPUFrequency : SINGLE;
var
  li     : TLargeInteger;
begin
  QueryPerformanceFrequency(li);
  Result := li.QuadPart / 10000;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := FloatToStrF(CPUFrequency, ffFixed, 6, 2);
end;


Don't know how you can get this for Win 3.1 though.

Regards,

Erik.
0
 

Author Comment

by:Rik
ID: 1336360
Didn't see your response on News Group.  Thank you, it worked!!
What is 'Quadpart', can't find any documentation on that?
0
 

Author Comment

by:Rik
ID: 1336361
Erik,

I'm not quite sure that solution worked.  It seemed to as it returned 119.20 when I was at work on a 120 MHz, but I am now at home and I am on a 200 MHz and it is returning 119.32.  Any ideas?  
0
 
LVL 3

Expert Comment

by:sperling
ID: 1336362
Funny.

According to the docs, the return value is the *true* CPU speed (Doesn't always match the vendors specs). It is calculated by reading the same counter that is used to generate the CPU frequency. It works on my computers, I'm sorry I can't help about the 200MHz (Is the 200MHz a Intel CPU, BTW?)

The quadpart is a 'Comp', which is borlands 64-bit signed integer value. It can't be used for much besides storing values and converting to floats, as you can't normally use DIV MOD and so on on a comp.


Regards,

Erik.
0
 

Author Comment

by:Rik
ID: 1336363
Erik,

Tried the code on a 75 MHz today and it too displayed 119.32 MHz.
Yes, the 200 MHz is an Intel.  When I boot up, the first thing displayed is 'Pentium = 200 MHz'.  If you hear of another way to get the clock speed, please let me know.  Thank you for your time.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now