C C 寫得乙個計時器用於檢查程式的處理資料效能

2021-06-29 05:02:01 字數 716 閱讀 2829

一般設計c/c++程式需要每秒能處理多少的資料,因此可以做乙個簡單的計時器來計時,**如下:

#ifndef _timer_h_  

#define _timer_h_

#include #include #include using namespace std;

class timer

timer(int pc):count(0),print_count(pc)

~timer()

void add()

} void begin()

void end()

};

void timer::openfile()

output << " " << "count" << " " << "total" << " " << "time" << " " << "frequence" << endl;

}#endif /*_timer_h_*/

呼叫方式如下:

[cpp]view plain

copy

timer timer(10000); 

//多少條資料列印一次

timer.begin();      //開始計時

for(;;)  

timer.end();        //最後列印一次

C C 計時器檢查程式效能

一般設計c c 程式需要每秒能處理多少的資料,因此可以做乙個簡單的計時器來計時,如下 cpp view plain copy ifndef timer h define timer h include include using namespace std class timer timer int...

乙個簡單的用於效能測算的計時器函式

我們常常採用gettickcount函式來測量程式的執行時間,但這個東西一次變化就要15 16ms,精度太低了。後果就是想要測量出個結果你得讓 反覆執行很多次。為此,我再次想到利用rdtsc指令。利用它給出的週期值,可以保證取到非常小的時間間隔。可惜的是該值不是直接的時間表達,還需要使用者按cpu主...

libevent學習筆記 第乙個程式 計時器

用libevent寫個定時器其實步驟不多 1 初始化libevent 2 設定事件 3 新增事件 4 進入迴圈 由於定時事件觸發之後,預設自動刪除,所以如果要一直計時,則要在 函式中重新新增定時事件。1 2 file timer.cc 3 author marrs chenchengxi993 gm...