国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

分享一個性能統計的簡單封裝類

2019-11-10 20:09:28
字體:
來源:轉載
供稿:網友

在查找問題,優化性能時,不免用到GetTickCount來統計函數耗時。

不斷的

DWord tick_beg = GetTickCount();

DWORD tick_end = GetTickCount();

DWORD tick_span = tick_end - tick_beg;

著實麻煩

簡單地封裝了一下。

主要提供的接口是

 AutoTick tick(__FUNCTIONW__);

利用作用域在對象析構時自動計算打印。

/********************************************************************created:	2016/11/11file   :	autotick.hauthor :	tulipwiki   :   purpose:	統計性能耗時            主要由析構計算,            GetCurrentConsume:  獲取對象構造到當前的耗時            GetLastConsume:    獲取上次計算時間點到當前時間點的耗時 *********************************************************************/#ifndef _AUTO_TICK_H_#define _AUTO_TICK_H_class AutoTick {public:    AutoTick(LPTSTR tip) { tip_ = tip; begin_ = GetTickCount(); last_tick_ = begin_;  }    AutoTick() { AutoTick(L"");}    ~AutoTick() {        end_ = GetTickCount();        DWORD span = end_ - begin_;        TCHAR str[1024] = { 0 };        _itow_s(span, str, 1024, 10);        std::wstring strout(L" span:/t/t");        std::wstring tip = tip_ + strout + str + std::wstring(L"/r/n");        OutputDebugString(tip.c_str());    }    // 獲取當前的耗時(當前 - 構造)    DWORD GetCurrentConsume(LPTSTR flag = NULL) {        DWORD tick_curr = GetTickCount() - begin_;        if (flag != NULL) {            TCHAR str[1024] = { 0 };            _itow_s(tick_curr, str, 1024, 10);            std::wstring strout(L"Contrust Consume:/t/t");            std::wstring tip = flag + strout + str + std::wstring(L"/r/n");            OutputDebugString(tip.c_str());        }        return tick_curr;    }    DWORD GetCurrentConsume(int index) {        TCHAR ach[64] = { 0 };        _itot_s(index, ach, 10);        GetCurrentConsume(ach);    }    // 獲取距離上次計時的耗時(當前 - 上次)    DWORD GetLastConsume(LPTSTR flag = NULL) {        DWORD curr_tick = GetTickCount();             DWORD tick_span = last_tick_ - curr_tick;        if (flag != NULL) {            TCHAR str[1024] = { 0 };            _itow_s(tick_span, str, 1024, 10);            std::wstring strout(L"Last Consume:/t/t");            std::wstring tip = flag + strout + str + std::wstring(L"/r/n");            OutputDebugString(tip.c_str());        }        last_tick_ = curr_tick;        return tick_span;    }    DWORD GetLastConsume(int index) {        TCHAR ach[64] = { 0 };        _itot_s(index, ach, 10);        return GetLastConsume(ach);    }    DWORD begin_;    DWORD end_;    DWORD last_tick_;    std::wstring tip_;};#endif
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湘阴县| 和顺县| 金秀| 修水县| 高邑县| 宝鸡市| 应城市| 浙江省| 涿州市| 蚌埠市| 凌云县| 广河县| 板桥市| 江川县| 泾阳县| 汶上县| 扬中市| 金坛市| 隆德县| 措勤县| 辽源市| 麟游县| 二连浩特市| 宝清县| 商丘市| 新营市| 海盐县| 鹤岗市| 集安市| 探索| 陵川县| 栖霞市| 开平市| 内黄县| 罗定市| 萝北县| 张掖市| 珲春市| 鹿泉市| 丰城市| 赤壁市|