Created
April 10, 2018 08:43
-
-
Save kumpeishiraishi/681ff990d7b3394bd57f7f5a897b6c0f to your computer and use it in GitHub Desktop.
chrono basic usage
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 <iostream> | |
# include <chrono> | |
int main() { | |
auto start = std::chrono::system_clock::now(); // use auto to skip typing std::chrono::system_clock::time_point | |
/* do something */ | |
auto end = std::chrono::system_clock::now(); | |
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count(); | |
/* | |
Trasnlate time unit to nanoseconds. | |
Other units are microseconds, milliseconds, seconds, minutes, hours. | |
*/ | |
std::cout << elapsed << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment