Skip to content

Instantly share code, notes, and snippets.

@RustingSword
Created June 13, 2020 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RustingSword/b18bc83df3be0644d85774ac85e3b3fe to your computer and use it in GitHub Desktop.
Save RustingSword/b18bc83df3be0644d85774ac85e3b3fe to your computer and use it in GitHub Desktop.
#include <chrono>
using std::chrono::system_clock;
using std::chrono::time_point;
using std::chrono::duration_cast;
using std::chrono::microseconds;
class Timer {
public:
void start() {
start_time = system_clock::now();
}
double elapsed_us() {
auto end_time = system_clock::now();
return duration_cast<microseconds>(end_time - start_time).count();
}
double elapsed_ms() {
return elapsed_us() / 1000.0;
}
double elapsed_sec() {
return elapsed_us() / 1000000.0;
}
private:
time_point<system_clock> start_time;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment