VC MFC中計算程式執行時間

2021-06-22 13:22:24 字數 1382 閱讀 8059

通過網上查閱資料,找到以下幾種vc中求取程式執行時間的方法:

方法一 利用gettickcount函式(ms)

**:cstringstr; 

longt1=

gettickcount();

//程式段開始前取得系統執行時間(ms) 

。。。。。。

//to do sth

longt2=

gettickcount();

//程式段結束後取得系統執行時間(ms) 

str.format(

"time:%dms

",t2

-t1);

//前後之差即程式執行時間 

afxmessagebox(str); 

方法二利用c/c++計時函式(s)

方法三 利用ctime類 獲取系統時間

**:cstringstr;

//獲取系統時間

ctime tm;tm=

ctime::getcurrenttime();

str=

tm.format(

"現在時間是%y年%m月%d日 %x");

afxmessagebox(str);

方法四  利用getlocaltime類獲取系統時間

systemtimest;

cstring strdate,strtime;

getlocaltime(

&st);

strdate.format(

"m----

",st.wyear,st.wmonth,st.wday);

strtime.format(

"-:-:-

",st.whour,st.wminute,st.wsecond);

afxmessagebox(strdate);

afxmessagebox(strtime);

VC MFC中計算程式 系統執行時間

vc mfc中計算程式 系統執行時間 skyseraph dec.30th 2010 hqu latest modified date dec.30th 2010 hqu 法一 利用gettickcount函式 獲取程式執行時間 longt1 gettickcount 程式段開始前取得系統執行時間 ...

VC MFC中計算程式 系統執行時間

vc mfc中計算程式 系統執行時間 skyseraph dec.30th 2010 hqu latest modified date dec.30th 2010 hqu 法一 利用gettickcount函式 獲取程式執行時間 longt1 gettickcount 程式段開始前取得系統執行時間 ...

計算程式執行時間

在長時間計算程式執行時間時,可以使用clock函式。clock比較通用,精度並不是特別的高,大約是10ms。但是對於長時間的計算的話,還是可以使用的。以下是一段示例程式,將幫助你理解 include stdio.h include memory.h include time.h define siz...