File indexing completed on 2025-01-18 10:12:44
0001
0002
0003
0004 #pragma once
0005
0006 #include <spdlog/fmt/fmt.h>
0007 #include <chrono>
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 namespace spdlog {
0029 class stopwatch
0030 {
0031 using clock = std::chrono::steady_clock;
0032 std::chrono::time_point<clock> start_tp_;
0033
0034 public:
0035 stopwatch()
0036 : start_tp_{clock::now()}
0037 {}
0038
0039 std::chrono::duration<double> elapsed() const
0040 {
0041 return std::chrono::duration<double>(clock::now() - start_tp_);
0042 }
0043
0044 void reset()
0045 {
0046 start_tp_ = clock::now();
0047 }
0048 };
0049 }
0050
0051
0052 namespace
0053 #ifdef SPDLOG_USE_STD_FORMAT
0054 std
0055 #else
0056 fmt
0057 #endif
0058 {
0059
0060 template<>
0061 struct formatter<spdlog::stopwatch> : formatter<double>
0062 {
0063 template<typename FormatContext>
0064 auto format(const spdlog::stopwatch &sw, FormatContext &ctx) -> decltype(ctx.out())
0065 {
0066 return formatter<double>::format(sw.elapsed().count(), ctx);
0067 }
0068 };
0069 }