//copy from spdlog
#pragma once
#include <chrono>
#include <iostream>
class stopwatch
{
using clock = std::chrono::steady_clock;
std::chrono::time_point<clock> start_tp_;
public:
stopwatch()
: start_tp_{clock::now()}
{}
std::chrono::duration<double> elapsed() const
{
return std::chrono::duration<double>(clock::now() - start_tp_);
}
void reset()
{
start_tp_ = clock::now();
}
};
#define STOP_WATCH(fun) do {\
stopwatch sw;\
fun();\
std::cout << #fun " Elapsed second: " << (sw.elapsed().count()) << '\n';\
}while(0)
代码计时工具类stop_watch
发布时间 2023-07-02 21:58:21作者: 算你牛