zoukankan      html  css  js  c++  java
  • 计时

     //取毫秒级时间精度(方法一):
      var
      t1,t2:int64;
      r1:int64;
      begin
      t1:=GetTickCount;//获取开始计数 WINDOWS API
      sleep(1000);{do...}//执行要计时的代码
      t2:=GetTickCount;//获取结束计数值
      r1:=t2-t1;//取得计时时间,单位毫秒(ms)
      showmessage(inttostr(r1));
      end

    //取毫秒级时间精度(方法二):
      //use DateUtils;//引用DateUtils单位
      var
      t1,t2:tdatetime;
      r1:int64;
      begin
      t1:=now();//获取开始计时时间
      sleep(1000);{do...}//执行要计时的代码
      t2:=now();//获取结束计时时间
      r1:=SecondsBetween(t2,t1);//取得计时时间,单位秒(s)
      r1:=MilliSecondsBetween(t2,t1);//取得计时时间,单位毫秒(ms)
      showmessage(inttostr(r1));
      end;

      //注:以上两种方式经本人测试好像只能产生0.01秒的计时精度

      //取系统级时间精度:
      var
      c1:int64;
      t1,t2:int64;
      r1:double;
      begin
      QueryPerformanceFrequency(c1);//WINDOWS API 返回计数频率(Intel86:1193180)(获得系统的高性能频率计数器在一毫秒内的震动次数)
      QueryPerformanceCounter(t1);//WINDOWS API 获取开始计数值
      sleep(1000);{do...}//执行要计时的代码
      QueryPerformanceCounter(t2);//获取结束计数值
      r1:=(t2-t1)/c1;//取得计时时间,单位秒(s)
      r1:=(t2-t1)/c1*1000;//取得计时时间,单位毫秒(ms)
      r1:=(t2-t1)/c1*1000000;//取得计时时间,单位微秒
      showmessage(floattostr(r1));
      end;

  • 相关阅读:
    安卓学习记录(四)——体温表APP
    2012ACM/ICPC亚洲区域赛成都赛区 总结
    poj 1011 Sticks(dfs+剪枝)
    uva 10891 Game of Sum (DP水题)
    poj 1077 Eight (bfs+康拓展开,A*&&IDA*算法)
    USACO Shaping Regions(离散化)
    poj 2741 Colored Cubes(dfs暴力枚举)
    LightOJ 1400 Employment (Stable Marriage)
    uva 10859 Placing Lampposts / Tree DP
    poj 1062 昂贵的聘礼(dfs+剪枝)
  • 原文地址:https://www.cnblogs.com/FuYan/p/3519268.html
Copyright © 2011-2022 走看看