Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[4873] [답변] 무념/ CPU 에 관한 정보를 얻으려면 ???
쉰들러 [ ] 1241 읽음    1998-10-13 10:47
// 아래 예제는 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.

----------------------------------------------------------------------
김영대씨의 홈페이지에서 가져 왔습니다.....^^;


+ -

관련 글 리스트
4873 [답변] 무념/ CPU 에 관한 정보를 얻으려면 ??? 쉰들러 1241 1998/10/13
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.