Created
June 13, 2020 03:04
-
-
Save RustingSword/b18bc83df3be0644d85774ac85e3b3fe 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
#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