Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Created December 5, 2019 06:03
Show Gist options
  • Save insaneyilin/45e2965dd8955435b0e064a9cc78b150 to your computer and use it in GitHub Desktop.
Save insaneyilin/45e2965dd8955435b0e064a9cc78b150 to your computer and use it in GitHub Desktop.
C++ 11 measure elapsed time
#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