Last active
November 2, 2023 00:30
-
-
Save jimdiroffii/b473b9f46c5b7c472581903ff4f24291 to your computer and use it in GitHub Desktop.
Calculate elapsed time in C++ program using chrono with high resolution and precision
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> // cout | |
#include <iomanip> // fixed, setprecision | |
#include <chrono> // time library | |
{ | |
auto startTime = std::chrono::high_resolution_clock::now(); | |
/* work */ | |
auto endTime = std::chrono::high_resolution_clock::now(); | |
std::chrono::duration<double> duration = endTime - startTime; | |
std::cout << "Time Elapsed: " << std::fixed << std::setprecision(6) << duration.count() << " seconds\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output:
Time Elapsed: 0.001729 seconds