zoukankan      html  css  js  c++  java
  • TStopWatch 基本知识

    System.Diagnostics.pas:

    Delphi includes a helpful unit called System.Diagnostics , which implements a

    TStopwatch record. It allows us to measure time events with a better precision than 1
    millisecond and has a pretty exhaustive public interface, as shown in the code fragment
    below:

     TStopwatch = record
      strict private
        class var FFrequency: Int64;
        class var FIsHighResolution: Boolean;
        class var TickFrequency: Double;
      strict private
        FElapsed: Int64;
        FRunning: Boolean;
        FStartTimeStamp: Int64;
        function GetElapsed: TTimeSpan;
        function GetElapsedDateTimeTicks: Int64;
        function GetElapsedMilliseconds: Int64;
        function GetElapsedTicks: Int64;
        class procedure InitStopwatchType; static;
      public
        class function Create: TStopwatch; static;
        class function GetTimeStamp: Int64; static;
        procedure Reset;
        procedure Start;
        class function StartNew: TStopwatch; static;
        procedure Stop;
        property Elapsed: TTimeSpan read GetElapsed;
        property ElapsedMilliseconds: Int64 read GetElapsedMilliseconds;
        property ElapsedTicks: Int64 read GetElapsedTicks;
        class property Frequency: Int64 read FFrequency;
        class property IsHighResolution: Boolean read FIsHighResolution;
        property IsRunning: Boolean read FRunning;
      end;
    

    To use a stopwatch, you first have to create it. You can call TStopwatch.Create to create a

    new stopped stopwatch or TStopwatch.StartNew to create a new started stopwatch. As
    TStopwatch is implemented as a record , there's no need to destroy a stopwatch object.
    When a stopwatch is started, it is measuring time. To start a stopwatch, call the Start
    method and to stop it, call the Stop method. The IsRunning property will tell you if the
    stopwatch is currently started. Call the Reset method to reset the stopwatch to zero.

    The TStopwatch contains a few functions that return the currently measured time. The

    most precise of them is ElapsedTicks , but as there is no built-in (public) function to
    convert this into standard time units, this function is hard to use. My recommendation is to
    just use the ElapsedMilliseconds property which will give you elapsed (measured) time
    in milliseconds.

  • 相关阅读:
    ajax收藏
    excel提取文本格式时分秒中数字的方法并计算成秒的公式
    vi编辑模式中按方向键变ABCD的解决方法
    IIS配置Url重写实现http自动跳转https的重定向方法
    IIS中启用目录浏览功能后不能下载未知扩展名文件的解决方法
    Nginx禁止IP访问,只允许域名访问
    nginx在Window平台http自动跳转https设置方法
    通过清理注册表方式清理window远程连接的历史记录
    DOS批处理添加IP域名,备份与恢复
    windows修改snmp端口号方法
  • 原文地址:https://www.cnblogs.com/BSor/p/9376439.html
Copyright © 2011-2022 走看看