Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- function CPUSpeed: Double;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- function TForm1.CPUSpeed: Double;
- const
- DelayTime = 500;
- 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
- mov TimerLo, eax
- mov TimerHi, edx
- end;
- Sleep(DelayTime);
- asm
- dw 310Fh
- 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.Button1Click(Sender: TObject);
- begin
- Label1.Caption := 'CPU Speed: ' + FloatToStr(CPUSpeed) + ' MHz';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement