⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stopwch1.pas

📁 在Windows NT使用I/O端口,包括装载,开始,卸载驱动程序的函数.
💻 PAS
字号:
unit Stopwch1;

{ Really quick and dirty high-res stopwatch using QueryPerformanceCounter.
  Needs to be spruced up with proper 64-bit arithmetic.
  Currently only good for one half-hour intervals

  03-31-98 GW Revisited and cleaned up a little
  05-06-96 GW Original

}

interface
uses windows;

Type
  TStopwatch = class
  public
    PerfCounterFreq: TLargeInteger; // Counts per second
    msDivider: integer;             // what to divide timestamps by to get ms
    
    StartTimeStamp: TLargeInteger;
    NewTimeStamp: TLargeInteger;
    
    LastElapsedTimems: integer;
    
    procedure Reset;
    constructor Create;
   { function ElapsedTimeSec: Real; }
    function ElapsedTimems: integer;
  end;

implementation

{--------------------------------}
constructor TStopwatch.Create;
{--------------------------------}
Var
  Success: boolean;
Begin
  Success := QueryPerformanceFrequency(PerfCounterFreq);
  msDivider := PerfCounterFreq.LowPart div 1000;
  Reset;
end;

{--------------------------------}
procedure TStopwatch.Reset;
{--------------------------------}
Var
  Success: boolean;
Begin
  Success := QueryPerformanceCounter(StartTimeStamp);
end;

{--------------------------------}
function TStopwatch.ElapsedTimems: integer;
{--------------------------------}
Var
  Success: boolean;
  NewLowPartSh, StartLowPartSh, ElapsedCountSh: integer;
  { shr avoids math problem with integer sign (ie: shr does not preserve sign) }
Begin
  Success := QueryPerformanceCounter(NewTimeStamp);
  NewLowPartSh   := NewTimeStamp.LowPart shr 1;
  StartLowPartSh := StartTimeStamp.LowPart shr 1;
  ElapsedCountSh := NewLowPartSh - StartLowPartSh;
  { answers from - $4000 0000 to +$3FFF FFFF, if -ve then assume timer wrapped }
  If ElapsedCountSh < 0 then ElapsedCountSh := ElapsedCountSh + $40000000;

  LastElapsedTimems := (ElapsedCountSh div msDivider) shl 1;
  Result := LastElapsedTimems;
end;

end.

⌨️ 快捷键说明

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