如何取得CPU的MHZ? |
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
如何取得CPU的MHZ?
以下程式也可以在windows NT/2000系列執行喔!
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function GetCpuSpeed: Comp; { function to return the CPU clock speed only. } { Usage: MessageDlg(Format('%.1f MHz', [GetCpuSpeed]), mtConfirmation, [mbOk], 0); } var t: DWORD; mhi, mlo, nhi, nlo: DWORD; t0, t1, chi, clo, shr32: Comp; begin shr32 := 65536; shr32 := shr32 * 65536; t := GetTickCount; while t = GetTickCount do begin end; asm DB 0FH DB 031H mov mhi,edx mov mlo,eax end; while GetTickCount < (t 1000) do begin end; asm DB 0FH DB 031H mov nhi,edx mov nlo,eax end; chi := mhi; if mhi < 0 then chi := chi shr32; clo := mlo; if mlo < 0 then clo := clo shr32; t0 := chi * shr32 clo; chi := nhi; if nhi < 0 then chi := chi shr32; clo := nlo; if nlo < 0 then clo := clo shr32; t1 := chi * shr32 clo; Result := (t1 - t0) / 1E6; end; procedure TForm1.Button1Click(Sender: TObject); begin caption:=floattostr(GetCpuSpeed) end; end.~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
附加檔案:00018989_unit1.pas
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |