timecount.pas

来自「一个求解TSP问题的例子,用delphi编写.有很好的参考价值」· PAS 代码 · 共 37 行

PAS
37
字号
unit TimeCount;

interface

uses
  Windows, SysUtils, Classes;

type
 { TCounter }
 TCounter = class(TComponent)
 private
   FFreq        : TLargeInteger;
   FStart       : TLargeInteger;
   function  GetElapsedSecs:string;
 public
   property ElapsedSecs : string read GetElapsedSecs;
   procedure StartTimeCount;
 end;

implementation

{---------------------------------------------------------------------------------}
procedure TCounter.StartTimeCount;
begin
  QueryPerformanceFrequency(FFreq);
  QueryPerformanceCounter(FStart);
end;
{---------------------------------------------------------------------------------}
function  TCounter.GetElapsedSecs:string;
var
 Stop : TLargeInteger;
begin
  QueryPerformanceCounter(Stop);
  Result := Format('%g', [(Stop - FStart)/ FFreq]);
end;

end.

⌨️ 快捷键说明

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