Last active
August 29, 2015 14:16
-
-
Save acidleaf/a97ed76c19c84249a749 to your computer and use it in GitHub Desktop.
C++11 std::chrono Timer
This file contains hidden or 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
#ifndef __ELAPSED_H__ | |
#define __ELAPSED_H__ | |
/* | |
Simple C++11 timer class to profile your function calls, etc. | |
Usage: | |
Elapsed e; | |
e.begin(); | |
myFunctionToBeProfiled(); | |
auto microseconds = e.end(); | |
*/ | |
#include <chrono> | |
class Elapsed { | |
protected: | |
std::chrono::high_resolution_clock::time_point _begin; | |
public: | |
void begin() { _begin = std::chrono::high_resolution_clock::now(); } | |
std::chrono::microseconds end() { | |
auto diff = std::chrono::high_resolution_clock::now() - _begin; | |
return std::chrono::duration_cast<std::chrono::microseconds>(diff); | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment