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

2021-07-24 01:57:40 字數 594 閱讀 1149

需求:

獲取一段程式執行的時間。

原理:

獲取程式開始和結束的時間並相減

即可。public static long currenttimemillis() - 與2023年1月1日的毫秒差。

用法:

long start=system.currenttimemillis();

...語句...

long end= 

system.currenttimemillis();

system.out.println("毫秒:"+(end-start)); 

模板方法設計模式:

abstract

class

gettime

public

abstract

void

runcode(); }

class

subtime

extends

gettime } 

}class

templatedemo }

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

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

Windows系統下獲取一段函式執行的時間

如果要獲取精確到毫秒的函式執行時間,在windows pc下可以使用queryperformancecounter介面 大致用法如下 include windows.h large integer freq,start,end double dtime 0 queryperformancefrequ...

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

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