Last active
July 24, 2023 23:42
-
-
Save PeterWaIIace/b4b66fc887442936670feca6ddb7093a to your computer and use it in GitHub Desktop.
timeit.cpp
This file contains 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 <functional> | |
#include <chrono> | |
#include <iostream> | |
using namespace std::chrono; | |
void timeit(std::function<void(void)> fn) | |
{ | |
auto start = high_resolution_clock::now(); | |
fn(); | |
auto stop = high_resolution_clock::now(); | |
auto duration = duration_cast<milliseconds>(stop - start); | |
std::cout << duration.count() << "ms" << std::endl; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lambda wrapper for measuring time elapsed while executing function. #PerformanceMeasurement #Cpp #Performance