Skip to content

Instantly share code, notes, and snippets.

@sy6sy2
Last active August 19, 2020 08:44
Show Gist options
  • Select an option

  • Save sy6sy2/46bbce356c953b5203ff426a330dfca6 to your computer and use it in GitHub Desktop.

Select an option

Save sy6sy2/46bbce356c953b5203ff426a330dfca6 to your computer and use it in GitHub Desktop.
[C++ snippets] #CPP

C++ snippets

Measure elapsed time

#include <chrono>

auto start = std::chrono::steady_clock::now();

  //
  //  Insert the code that will be timed
  //

auto end = std::chrono::steady_clock::now();

std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " µs" << std::endl;
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::nanoseconds> (end - start).count() << " ns" << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment