以前因爲想統計代碼中每一個模塊加載時長,所以寫了一個模塊加載時長統計類,使用起來也是超級方便,只須要定義一個宏便可ios
使用方式以下:windows
void func() { CONSUMING_OUTPUT("className"); }
void func() { ... { //funcation code CONSUMING_OUTPUT("code"); } ... }
class A() { ... CONSUMING_OUTPUT("A life time"); }
//性能查看方便類代碼以下函數
#include <time.h> #include <windows.h> #include <iostream> struct PerformanceCheck { public: PerformanceCheck(const std::wstring & message) :m_Message(message) { m_Start = clock(); } ~PerformanceCheck() { m_End = clock(); wchar_t str[1024]; wsprintf(str, L"%s:%d\n", m_Message.c_str(), (long)((double)(m_End - m_Start) / (double)(CLOCKS_PER_SEC)* 1000.0)); #ifdef _DEBUG OutputDebugString(str); #else RLBase::WriteProgramLogNoMask(str); #endif // DEBUG } private: clock_t m_Start; clock_t m_End; std::wstring m_Message; }; #define PerformanceOutput //是否啓用性能輸出 #ifdef PerformanceOutput #define CONSUMING_OUTPUT(a) PerformanceCheck c(a) #else #define CONSUMING_OUTPUT(a) #endif