main.pas

来自「High Accuracy Timer Component」· PAS 代码 · 共 86 行

PAS
86
字号
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
  StdCtrls, Buttons;

type

  TForm1 = class(TForm)
    btnStart: TBitBtn;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  Mem: Cardinal;

implementation

uses SZTimer;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  btnStart.Click;
end;

procedure TForm1.btnStartClick(Sender: TObject);
var
  t: TSZTimer;
  d: extended;
  i: integer;
begin
  SZBeforeBenchmark;

  memo1.Clear;

  t.Start; sleep(1000); t.Stop;

  Memo1.Lines.Add('Sleep 1000ms : '+t.PrintRDTSC+' CPU Clock Cycles');
  Memo1.Lines.Add('Sleep 1000ms : '+t.Print);

  Memo1.Lines.Add('');
  Memo1.Lines.Add('CPU Speed : '+format('%.6n MHz',[t.ElapsedRDTSC/1000000]));
  Memo1.Lines.Add('');


  t.Start;

  d:=0;
  for i:=0 to 255 do
    d:=d+sin(4/3 * PI);

  t.Stop;

  Memo1.Lines.Add(format('sin = %f : %s CPU Clock Cycles',[d, t.PrintRDTSC]));
  Memo1.Lines.Add('');

  t.Start;

  d:=0;
  for i:=0 to 255 do
    d:= d + sin(4/3 * PI) + sin(4/3 * PI);

  t.Stop;

  Memo1.Lines.Add(format(' sin + sin = %f : %s CPU Clock Cycles',[d, t.PrintRDTSC]));
  Memo1.Lines.Add('');

  SZAfterBenchmark;


end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?