Compile with -std=c++0x.
double duration = time([](){
do_some_heavy_stuff();
})| #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(); | |
| } |