// 아래 예제는 Intel Pentium CPU 일때 정확히 동작하며
// AMD등 다른 제작업체의 CPU의 클럭은 아래 사이트에 정보가 있습니다
//
//
http://www.amd.com/swdev/swdev.html (AMD)
//
http://www.cyrix.com/developers/software/isv.htm (Cyrix)
//
http://support.intel.com (Intel)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dial
ogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure FormActivate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
SI: TSystemInfo;
implementation
{$R *.DFM}
// CPU의 클럭속도를 구한다
function GetCPUSpeed: Double;
const
DelayTime = 500; // measure time in ms
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;
SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
// CPU type을 구한다
GetSystemInfo(SI);
(* 주석을 열어서 본인의 CPU type을 확인해 보세요
case Si.dwProcessorType of
386 : ShowMessage('Intel 386');
486 : ShowMessage('Intel 486');
586 : ShowMessage('Intel Pentium');
end;
*)
// Timer 의 OnTimer일때만 CPU speed 를 구한다
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
if Si.dwProcessorType <> 586 then // Intel Pentium 급 이상이면 CPU sp
eed 를 구한다
System.Exit;
try
Label1.Caption := Format('%f MHz', [GetCPUSpeed]);
except // 이름만 'Intel Pentium' 인 CPU가 있음....
Label1.Caption := '? MHz';
end;
Application.ProcessMessages;
Timer1.Enabled := True;
end;
end.
----------------------------------------------------------------------
김영대씨의 홈페이지에서 가져 왔습니다.....^^;