Skip to content

Instantly share code, notes, and snippets.

@Iksas
Created August 31, 2025 22:22
Show Gist options
  • Select an option

  • Save Iksas/72dc2b576c63ce48d19ee3ed464f9422 to your computer and use it in GitHub Desktop.

Select an option

Save Iksas/72dc2b576c63ce48d19ee3ed464f9422 to your computer and use it in GitHub Desktop.
C++ benchmark template
#include <iostream>
#include <chrono>
using namespace std;
int main()
{
chrono::steady_clock::time_point begin = chrono::steady_clock::now();
// The code to benchmark goes here...
chrono::steady_clock::time_point end = chrono::steady_clock::now();
cout << "Time difference = " << chrono::duration_cast<std::chrono::seconds>(end - begin).count() << "[s]" << std::endl;
cout << "Time difference = " << chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "[ms]" << std::endl;
cout << "Time difference = " << chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[us]" << std::endl;
cout << "Time difference = " << chrono::duration_cast<std::chrono::nanoseconds> (end - begin).count() << "[ns]" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment