Created
December 5, 2019 06:03
-
-
Save insaneyilin/45e2965dd8955435b0e064a9cc78b150 to your computer and use it in GitHub Desktop.
C++ 11 measure elapsed time
This file contains hidden or 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 <thread> | |
| #include <chrono> | |
| void foo() { | |
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
| } | |
| int main(int argc, char **argv) { | |
| auto start_time = std::chrono::high_resolution_clock::now(); | |
| foo(); | |
| auto end_time = std::chrono::high_resolution_clock::now(); | |
| auto diff = end_time - start_time; | |
| std::cout << "elapsed time: " | |
| << std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() | |
| << " ms" << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment