windows下乙個用於效能分析的打點計時C 類

2021-08-28 23:47:25 字數 2207 閱讀 3360

最近在改造公司舊系統**(c++),需要查詢某個函式效能底下原因,所以自己寫了乙個打點計時類用於效能分析,其中最主要的取時間函式getsystimemicros由同事(楊成)提供。

標頭檔案 performancecounter.h

裡面時間值單位為微秒,如果計時打點超過20000個,請修改標頭檔案中counter_array_size。

#pragma once

#include #define counter_array_size 20000

class cperformancecounter

;

實現檔案 performancecounter.cpp

#include "performancecounter.h"

#include #include #include #define epochfiletime (116444736000000000ul)

cperformancecounter::cperformancecounter(const char* pinfo)

else

}cperformancecounter::~cperformancecounter()

void cperformancecounter::debugallelapseinfo()

void cperformancecounter::debugelapseinfo(const int64_t usedtime, const char* info)

; sprintf(tick_expr, "%s: %s elpase time=%ds,%dms,%dus\n", m_info, null == info ? "" : info, second, millise, micros);

outputdebugstringa(tick_expr);

}void cperformancecounter::start()

int64_t cperformancecounter::tick()

void cperformancecounter::debugeverytickelapseinfo()

}int64_t cperformancecounter::getstarttime() const

int64_t cperformancecounter::getallelapseusec()

int cperformancecounter::gettickmaxelapseindex()

} return result;

}int cperformancecounter::gettickminelapseindex()

} return result;

}int cperformancecounter::getcount() const

int64_t cperformancecounter::getticktime(const int index)

return m_countertimes[index];

}int64_t cperformancecounter::gettickelapseusec(const int index)

return getvalidtickelapseusec(index);

}int64_t cperformancecounter::getvalidtickelapseusec(const int index)

bool cperformancecounter::isstartcount(const int index)

int64_t cperformancecounter::getsystimemicros()

使用範例:

cperformancecounter performancecounter("refresh original");

crefreshrdbycoriginalimpl refreshrdbyc;

performancecounter.start();

for (int i = 0; i < performance_test_run_num; i++)

performancecounter.debugeverytickelapseinfo(); // 列印每個打點計時花費時間

performancecounter.debugallelapseinfo(); // 列印所有打點計時花費時間

}

下乙個天亮

用起伏的背影 擋住哭泣的心 有些故事 不必說給 每個人聽 許多眼睛 看的太淺太近 錯過我沒被看見 那個自己 用簡單的言語 解開超載的心 有些情緒 是該說給 懂的人聽 你的熱淚 比我激動憐惜 我發誓要更努力 更有勇氣 等下乙個天亮 去上次牽手賞花那裡散步好嗎 有些積雪會自己融化 你的肩膀是我豁達的天堂...

下乙個排列

給定乙個若干整數的排列,給出按正數大小進行字典序從小到大排序後的下乙個排列。如果沒有下乙個排列,則輸出字典序最小的序列。樣例 左邊是原始排列,右邊是對應的下乙個排列。1,2,3 1,3,2 3,2,1 1,2,3 1,1,5 1,5,1 思路 1 先從右到左找到第乙個不屬於非最大字典序排列的元素l,...

下乙個排列

給定乙個若干整數的排列,給出按正數大小進行字典序從小到大排序後的下乙個排列。如果沒有下乙個排列,則輸出字典序最小的序列。左邊是原始排列,右邊是對應的下乙個排列。1,2,3 1,3,2 3,2,1 1,2,3 1,1,5 1,5,1 剛開始看這個題目沒有看懂,在網上蒐集一番資料後,懂得了題目想要做的事...