diff options
author | Emma Miler <emma.pi@protonmail.com> | 2022-12-02 23:00:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 23:00:33 +0100 |
commit | 2d59006262d6e45f41ee325af78433475884dca4 (patch) | |
tree | 939c84779bf6a455102c74937f238a0ec05698eb /include/spdlog/stopwatch.h | |
parent | be78dbacc5dcc95e7d9be503d61ceb5de640c661 (diff) | |
download | NorthstarLauncher-2d59006262d6e45f41ee325af78433475884dca4.tar.gz NorthstarLauncher-2d59006262d6e45f41ee325af78433475884dca4.zip |
Move include directory (#337)v1.11.0-rc1
* Move include directory to shared folder
This commit moves the `include` directory from the NorthstarDLL project folder to the solution folder. This allows both the DLL and Launcher project to target it properly.
* Fix filters
* Update memalloc.h
* Fix filters
* Update NorthstarLauncher.vcxproj
* Remove stuff from other PR
* Update NorthstarLauncher.vcxproj
* Update NorthstarLauncher.vcxproj
* Update NorthstarDLL.vcxproj
Diffstat (limited to 'include/spdlog/stopwatch.h')
-rw-r--r-- | include/spdlog/stopwatch.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h new file mode 100644 index 00000000..bb976b19 --- /dev/null +++ b/include/spdlog/stopwatch.h @@ -0,0 +1,61 @@ +// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) + +#pragma once + +#include <spdlog/fmt/fmt.h> + +// Stopwatch support for spdlog (using std::chrono::steady_clock). +// Displays elapsed seconds since construction as double. +// +// Usage: +// +// spdlog::stopwatch sw; +// ... +// spdlog::debug("Elapsed: {} seconds", sw); => "Elapsed 0.005116733 seconds" +// spdlog::info("Elapsed: {:.6} seconds", sw); => "Elapsed 0.005163 seconds" +// +// +// If other units are needed (e.g. millis instead of double), include "fmt/chrono.h" and use "duration_cast<..>(sw.elapsed())": +// +// #include <spdlog/fmt/chrono.h> +//.. +// using std::chrono::duration_cast; +// using std::chrono::milliseconds; +// spdlog::info("Elapsed {}", duration_cast<milliseconds>(sw.elapsed())); => "Elapsed 5ms" + +namespace spdlog { +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(); + } +}; +} // namespace spdlog + +// Support for fmt formatting (e.g. "{:012.9}" or just "{}") +namespace fmt { +template<> +struct formatter<spdlog::stopwatch> : formatter<double> +{ + template<typename FormatContext> + auto format(const spdlog::stopwatch &sw, FormatContext &ctx) -> decltype(ctx.out()) + { + return formatter<double>::format(sw.elapsed().count(), ctx); + } +}; +} // namespace fmt |