Created
December 27, 2013 06:44
-
-
Save Fuyutsubaki/8143471 to your computer and use it in GitHub Desktop.
デバックタイマー。呼び出された回数と時間を教えてくれる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<chrono> | |
#include<string> | |
#include<list> | |
class DebugTimer | |
{ | |
struct Data | |
{ | |
Data(const std::string&id) | |
:id(id) | |
{ | |
Get_List().push_back(this); | |
} | |
std::chrono::system_clock::duration time; | |
int count = 0; | |
std::string id; | |
}; | |
public: | |
template<class ID_class> | |
class Timer | |
{ | |
public: | |
Timer() | |
:begin(std::chrono::system_clock::now()) | |
{} | |
~Timer() | |
{ | |
get().time += std::chrono::system_clock::now() - begin; | |
++get().count; | |
} | |
private: | |
const std::chrono::system_clock::time_point begin; | |
inline static Data &get(){ static Data c(typeid(ID_class).name()); return c; } | |
}; | |
//何もしないタイマー。release時にでも | |
template<class> | |
class No_Debug_Timer{}; | |
inline static std::list<Data*> &Get_List(){ static std::list<Data*> list; return list; } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment