VC中监测函数运行时间

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=============

 

 

posted @ 2013-06-18 18:09  vranger  Views(466)  Comments(0Edit  收藏  举报