cxx-benchmarks/measure_time.h

21 行
526 B
C++

#pragma once
#include <chrono>
#include <iostream>
template<typename Callable>
void measure_time(Callable&& callable) {
using namespace std::chrono;
steady_clock::time_point t_start = steady_clock::now();
callable();
duration<double> time_span = duration_cast<duration<double>>(steady_clock::now() - t_start);
std::cout << "took " << time_span.count() << " seconds\n";
}
template<typename Callable>
void measure_time_with_dry_run(Callable&& callable) {
callable();
measure_time(std::forward<Callable>(callable));
}