File indexing completed on 2025-07-02 08:50:53
0001
0002
0003
0004 #pragma once
0005
0006 #include <chrono>
0007 #include <spdlog/fmt/fmt.h>
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 namespace spdlog {
0030 class stopwatch {
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 std::chrono::duration<double> elapsed() const {
0039 return std::chrono::duration<double>(clock::now() - start_tp_);
0040 }
0041
0042 std::chrono::milliseconds elapsed_ms() const {
0043 return std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - start_tp_);
0044 }
0045
0046 void reset() { start_tp_ = clock::now(); }
0047 };
0048 }
0049
0050
0051 namespace
0052 #ifdef SPDLOG_USE_STD_FORMAT
0053 std
0054 #else
0055 fmt
0056 #endif
0057 {
0058
0059 template <>
0060 struct formatter<spdlog::stopwatch> : formatter<double> {
0061 template <typename FormatContext>
0062 auto format(const spdlog::stopwatch &sw, FormatContext &ctx) const -> decltype(ctx.out()) {
0063 return formatter<double>::format(sw.elapsed().count(), ctx);
0064 }
0065 };
0066 }