Last active
December 6, 2020 17:48
-
-
Save blgnksy/b38dedcb91553e60a408ea6a3d19a718 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> | |
#include <iostream> | |
#include <thread> | |
class Timer { | |
private: | |
std::chrono::time_point<std::chrono::high_resolution_clock> mStart; | |
public: | |
Timer() { mStart = std::chrono::high_resolution_clock::now(); } | |
~Timer() { stop(); } | |
void stop() { | |
auto end = std::chrono::high_resolution_clock::now(); | |
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(mStart) | |
.time_since_epoch() | |
.count(); | |
auto stop = std::chrono::time_point_cast<std::chrono::microseconds>(end) | |
.time_since_epoch() | |
.count(); | |
auto duration = stop - start; | |
std::cout << duration * 0.001 << " ms\n"; | |
} | |
}; | |
using namespace std::literals::chrono_literals; | |
int main() | |
{ | |
{ | |
auto t = Timer(); | |
std::this_thread::sleep_for(1s); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment