Last active
July 14, 2020 15:03
-
-
Save tmsampson/0b4151fbdce9898384dae23521278894 to your computer and use it in GitHub Desktop.
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 <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