C 新增測量執行時間

2022-01-31 21:31:50 字數 1045 閱讀 1707

使用模組化開發,每個模組都有初始化功能,初始化功能可能包括:載入配置表,初始化事件,初始化設定

那麼如果想測量每個模組的init時間呢?net框架已經提供了測量執行的方法

system.diagnostics

system.diagnostics 命名空間包含具有以下功能的型別:能讓你與系統程序、事件日誌和效能計數器之間進行互動。

子命名空間包含具有以下功能的型別:與**分析工具進行互動,支援協定,擴充套件對應用程式監控和檢測的設計時支援,使用 windows 事件跟蹤 (etw) 跟蹤子系統來記錄事件資料,在事件日誌中進行讀取和寫入,收集效能資料,以及讀取和寫入除錯符號資訊。

提供一組方法和屬性,可用於準確地測量執行時間。

msdn:

public

class

performancehelper

public

static

void addwatch(string

outputstr, action del)

stopwatch.stop();

//停止監視

timespan timespan = stopwatch.elapsed; //

獲取當前例項測量得出的總時間

double millseconds = timespan.totalmilliseconds;//

總毫秒數

decimal seconds = (decimal)millseconds /1000m;

debug.log(

string.format(outputstr, seconds.tostring("

f7"))); //

7位精度

}

else}}

}

public

class

gamesettings"

,loadconfig);

}public

void

loadconfig()

}

C語言 程式執行時間測量

今天在做乙個大資料檔案建立的時候,為了測量建立所用的時間,特意研究了下,windows下時間的獲取 1 55ms解析度的計時 標頭檔案 include gettickcount 用法 dword dwstart gettickcount functon your program.dword dwen...

測量執行時間StopWatch類

using system using system.diagnostics using system.threading class program ts.hours,ts.minutes,ts.seconds,ts.milliseconds 10 console.writeline elapsed...

timeofday測量程式執行時間

2.時間的測量 有時候我們要計算程式執行的時間.比如我們要對演算法進行時間分析.這個時候可以使用下面這個函式.include int gettimeofday struct timeval tv,struct timezone tz strut timeval gettimeofday將時間儲存在結...