Skip to content

Instantly share code, notes, and snippets.

@acidleaf
Last active August 29, 2015 14:16
Show Gist options
  • Save acidleaf/a97ed76c19c84249a749 to your computer and use it in GitHub Desktop.
Save acidleaf/a97ed76c19c84249a749 to your computer and use it in GitHub Desktop.
C++11 std::chrono Timer
#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