944,110 Members | Top Members by Rank

Ad:
0

Get the speed of your processor (CPU)

by on Dec 17th, 2004
This is Delphi code, just testing if there is some interest.
Pascal and Delphi Code Snippet (Toggle Plain Text)
  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.  
Comments on this Code Snippet
Dec 17th, 2004
0

Re: Get the speed of your processor (CPU)

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?
The Queen of DaniWeb
cscgal is online now Online
13,646 posts
since Feb 2002
Dec 18th, 2004
0

Re: Get the speed of your processor (CPU)

I think Borland gave one of the older versions (4?) of Delphi away for free. Check their site.
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Dec 21st, 2006
0

Re: Get the speed of your processor (CPU)

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).
Newbie Poster
eddie-jdp is offline Offline
9 posts
since Dec 2006
Message:
Previous Thread in Pascal and Delphi Forum Timeline: so...tutorials, tips and tricks, and many more....
Next Thread in Pascal and Delphi Forum Timeline: Synthesize a program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC