Skip to content

Instantly share code, notes, and snippets.

@tmsampson
Last active July 14, 2020 15:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tmsampson/0b4151fbdce9898384dae23521278894 to your computer and use it in GitHub Desktop.
//------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <chrono>
//------------------------------------------------------------------------------------------------------------------------------
int main()
{
// Start timer
auto start = std::chrono::high_resolution_clock::now();
//--------------------------------------------------------------------------------------------------------------------------
// [YOUR CODE HERE]
//--------------------------------------------------------------------------------------------------------------------------
// Stop timer
auto end = std::chrono::high_resolution_clock::now();
auto duration = (end - start);
auto us = std::chrono::duration_cast<std::chrono::microseconds>(duration); // Microsecond (as int)
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration); // Milliseconds (as int)
const float ms_fractional = static_cast<float>(us.count()) / 1000; // Milliseconds (as float)
std::cout << "Duration = " << us.count() << "µs (" << ms_fractional << "ms)" << std::endl;
}
//------------------------------------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment