Created
October 14, 2016 14:37
-
-
Save mcleary/1bf76fae686ce8d9c21bbad9167085f2 to your computer and use it in GitHub Desktop.
Timing a function with <chrono>
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 really_long_function() | |
{ | |
using namespace std::chrono; | |
// Very cool user defined literals for duration representation | |
std::this_thread::sleep_for(3000ms); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
using namespace std::chrono; | |
auto begin_time = steady_clock::now(); | |
really_long_function(); | |
auto end_time = steady_clock::now(); | |
auto function_time = duration_cast<milliseconds>(end_time - begin_time); | |
std::cout << function_time.count() << "ms" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment