Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Created October 23, 2012 20:24
Show Gist options
  • Save juliangruber/3941303 to your computer and use it in GitHub Desktop.
Save juliangruber/3941303 to your computer and use it in GitHub Desktop.
c++0x timing utility
#include <chrono>
#include <functional>
double time (std::function<void ()> fn) {
using namespace std::chrono;
high_resolution_clock::time_point start, end;
start = high_resolution_clock::now();
fn();
end = high_resolution_clock::now();
duration<double> span;
return duration_cast<duration<double>>(end-start).count();
}

Compile with -std=c++0x.

double duration = time([](){
  do_some_heavy_stuff();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment