VS2015測試某一段程式執行時間

2021-07-25 11:52:00 字數 582 閱讀 7560

#include

#include

#include

using namespace std;

方法一:使用gettickcount()函式獲取系統時間,程式執行前後系統時間差值就是該程式段的執行時間!

int main()

long end_time = gettickcount(); //獲取此程式段開始執行時間

cin.get();

return 0;

方法二:使用clock()函式,原理和方法一類似

int main()

std::cout << std::endl;

steady_clock::time_point t2 = steady_clock::now();

durationtime_span = duration_cast>(t2 - t1);

std::cout << "it took me " << time_span.count() << " seconds.";

std::cout << std::endl;

return 0;

}

測試某一段程式執行時間的方法

前兩天我為了將 casia 資料集進行水平映象,所以自己寫了了個簡單的程式來用。方法很簡單,就是借助 opencv 逐畫素進行操作。因為是逐畫素進行操作,所以我也料想到會很慢。為了測試一下速度,我就在網上查了查別人用的方法。網上有很多方法,我找了了簡單的。用到的標頭檔案是 裡面有個函式clock 網...

模板方法模式,(獲取一段程式執行的時間)

需求 獲取一段程式執行的時間。原理 獲取程式開始和結束的時間並相減 即可。public static long currenttimemillis 與1970年1月1日的毫秒差。用法 long start system.currenttimemillis 語句.long end system.cur...

java Java計算一段程式的執行時間

long starttime system.nanotime 獲取開始時間 測試的程式 long endtime system.nanotime 獲取結束時間 system.out.println 執行時間是 starttime endtime ns 輸出執行時間long starttime sys...