Get the speed of your processor (CPU)

vegaseat vegaseat is offline Offline Dec 17th, 2004, 12:33 am |
0
This is Delphi code, just testing if there is some interest.
Quick reply to this message  
Pascal and Delphi Syntax
  1. // The Windows form is simple, having only one button titled
  2. // "Click to get CPU speed" and a label to show the results
  3. // written for Delphi 3.0 (vegaseat)
  4.  
  5. unit CPUspeedz;
  6.  
  7. interface
  8.  
  9. uses
  10. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  11. StdCtrls;
  12.  
  13. type
  14. TForm1 = class(TForm)
  15. Button1: TButton;
  16. Label1: TLabel;
  17. procedure Button1Click(Sender: TObject);
  18. private
  19. { Private declarations }
  20. public
  21. { Public declarations }
  22. end;
  23.  
  24. var
  25. Form1: TForm1;
  26.  
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. // get the speed of your CPU in MHz
  33. function GetCPUSpeed: Double;
  34. const
  35. DelayTime = 500;
  36. var
  37. TimerHi, TimerLo: DWORD;
  38. PriorityClass, Priority: Integer;
  39. begin
  40. PriorityClass := GetPriorityClass(GetCurrentProcess);
  41. Priority := GetThreadPriority(GetCurrentThread);
  42.  
  43. SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  44. SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
  45.  
  46. Sleep(10);
  47. asm
  48. dw 310Fh
  49. mov TimerLo, eax
  50. mov TimerHi, edx
  51. end;
  52. Sleep(DelayTime);
  53. asm
  54. dw 310Fh
  55. sub eax, TimerLo
  56. sbb edx, TimerHi
  57. mov TimerLo, eax
  58. mov TimerHi, edx
  59. end;
  60.  
  61. SetThreadPriority(GetCurrentThread, Priority);
  62. SetPriorityClass(GetCurrentProcess, PriorityClass);
  63.  
  64. Result := TimerLo / (1000 * DelayTime);
  65. end;
  66.  
  67.  
  68. procedure TForm1.Button1Click(Sender: TObject);
  69. begin
  70. Label1.Caption := (Format('Your CPU speed: %f MHz', [GetCPUSpeed]));
  71. end;
  72.  
  73. end.
  74.  
0
cscgal cscgal is offline Offline | Dec 17th, 2004
Cool. I've heard of the language but never had experience with it. Is it a proprietary language? Where could one get access to a compiler?
 
0
vegaseat vegaseat is offline Offline | Dec 18th, 2004
I think Borland gave one of the older versions (4?) of Delphi away for free. Check their site.
 
0
eddie-jdp eddie-jdp is offline Offline | Dec 21st, 2006
In September 2006 borland released a free version of the Delphi compiler.

Look for Turbo Delphi (explorer edition) on borland's website http://www.borland.com or CodeGear's website http://www.codegear.com

Eddie

P.S. CodeGear is a new company (2006) that I believe is owned by Borland. CodeGear is taking over development of some of Borland's developer tools (like Delphi).
 
 

Message:


Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC