Advertisement
miguelhosttimer

retorna a frequência do processador delphi

May 16th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.37 KB | None | 0 0
  1.    unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Label1: TLabel;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.     function CPUSpeed: Double;
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.dfm}
  27.  
  28. function TForm1.CPUSpeed: Double;
  29. const
  30.   DelayTime = 500;
  31. var
  32.   TimerHi, TimerLo: DWORD;
  33.   PriorityClass, Priority: Integer;
  34. begin
  35.   PriorityClass := GetPriorityClass(GetCurrentProcess);
  36.   Priority := GetThreadPriority(GetCurrentThread);
  37.   SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  38.   SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  39.   Sleep(10);
  40.   asm
  41.     dw 310Fh
  42.     mov TimerLo, eax
  43.     mov TimerHi, edx
  44.   end;
  45.   Sleep(DelayTime);
  46.   asm
  47.     dw 310Fh
  48.     sub eax, TimerLo
  49.     sbb edx, TimerHi
  50.     mov TimerLo, eax
  51.     mov TimerHi, edx
  52.   end;
  53.   SetThreadPriority(GetCurrentThread, Priority);
  54.   SetPriorityClass(GetCurrentProcess, PriorityClass);
  55.   Result := TimerLo / (1000.0 * DelayTime);
  56. end;
  57.  
  58. procedure TForm1.Button1Click(Sender: TObject);
  59. begin
  60.   Label1.Caption := 'CPU Speed: ' + FloatToStr(CPUSpeed) + ' MHz';
  61. end;
  62.  
  63. end.
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement