Skip to content

Instantly share code, notes, and snippets.

@PeterWaIIace
Last active July 24, 2023 23:42
Show Gist options
  • Save PeterWaIIace/b4b66fc887442936670feca6ddb7093a to your computer and use it in GitHub Desktop.
Save PeterWaIIace/b4b66fc887442936670feca6ddb7093a to your computer and use it in GitHub Desktop.
timeit.cpp
#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;
};
@PeterWaIIace
Copy link
Author

lambda wrapper for measuring time elapsed while executing function. #PerformanceMeasurement #Cpp #Performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment