//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)
标签:std,clock,watch,chrono,stop,tp,start,计时,now
From: https://www.cnblogs.com/suanniniu/p/17521509.html