VC++编程时,经常会监控某个算法的计算时间,以确定算法的效率。
编码举例如下,

 

1     //========start: algorithm time=============
2     //
3     SYSTEMTIME st1;
4     GetLocalTime(&st1);//获取算法处理前,系统时间
5     //
6     //========start: algorithm time=============

 

 。。。。。。。。// algorithm processing

 

 1     //========end: algorithm time=============
 2     //
 3     SYSTEMTIME st2;
 4     GetLocalTime(&st2);//获取算法结束时系统时间
 5     float tm1,tm2;
 6     float ts1,ts2;
 7     float tms1,tms2;
 8     tm1=st1.wMinute;
 9     tm2=st2.wMinute;//
10     ts1=st1.wSecond;
11     ts2=st2.wSecond;//
12     tms1=st1.wMilliseconds;
13     tms2=st2.wMilliseconds;//毫秒
14 
15     if (tms2<tms1)
16         {
17         tms2+=1000;
18         ts2-=1;
19         }
20     if (ts2<ts1)
21         {
22         ts2+=60;
23         tm2-=1;
24         }
25     if (tm2<tm1)
26         {
27         tm2+=60;
28         }
29     CString time;
30     time.Format("CSMesh Topo,run time consume:%f min,%f s,%f ms",tm2-tm1,ts2-ts1,tms2-tms1);
31     AfxMessageBox(time);
32     //
33     //========end: algorithm time=============

 

 

相关文章:

  • 2021-12-24
  • 2022-03-06
  • 2021-09-20
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2021-07-25
  • 2022-02-26
  • 2022-12-23
  • 2021-12-11
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案