aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/spdlog/tests/test_stopwatch.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-24 10:19:24 +0200
committerGitHub Enterprise <[email protected]>2025-10-24 10:19:24 +0200
commit0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00 (patch)
treebe7c96101bf9c91615f04412c7bafe156a3d6ac8 /thirdparty/spdlog/tests/test_stopwatch.cpp
parentchangelog (diff)
downloadzen-0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00.tar.xz
zen-0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00.zip
in-tree spdlog (#602)
move spdlog into the tree to remove dependency on vcpkg::spdlog, to allow diverging from the official version and evolve it to fit better with OTLP logging requirements
Diffstat (limited to 'thirdparty/spdlog/tests/test_stopwatch.cpp')
-rw-r--r--thirdparty/spdlog/tests/test_stopwatch.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/thirdparty/spdlog/tests/test_stopwatch.cpp b/thirdparty/spdlog/tests/test_stopwatch.cpp
new file mode 100644
index 000000000..b1b4b191c
--- /dev/null
+++ b/thirdparty/spdlog/tests/test_stopwatch.cpp
@@ -0,0 +1,42 @@
+#include "includes.h"
+#include "test_sink.h"
+#include "spdlog/stopwatch.h"
+
+TEST_CASE("stopwatch1", "[stopwatch]") {
+ using std::chrono::milliseconds;
+ using clock = std::chrono::steady_clock;
+ milliseconds wait_ms(500);
+ milliseconds tolerance_ms(250);
+ auto start = clock::now();
+ spdlog::stopwatch sw;
+ std::this_thread::sleep_for(wait_ms);
+ auto stop = clock::now();
+ auto diff_ms = std::chrono::duration_cast<milliseconds>(stop - start);
+ REQUIRE(sw.elapsed() >= diff_ms);
+ REQUIRE(sw.elapsed() <= diff_ms + tolerance_ms);
+}
+
+TEST_CASE("stopwatch2", "[stopwatch]") {
+ using spdlog::sinks::test_sink_st;
+ using std::chrono::duration_cast;
+ using std::chrono::milliseconds;
+ using clock = std::chrono::steady_clock;
+
+ clock::duration wait_duration(milliseconds(500));
+ clock::duration tolerance_duration(milliseconds(250));
+
+ auto test_sink = std::make_shared<test_sink_st>();
+
+ auto start = clock::now();
+ spdlog::stopwatch sw;
+ spdlog::logger logger("test-stopwatch", test_sink);
+ logger.set_pattern("%v");
+ std::this_thread::sleep_for(wait_duration);
+ auto stop = clock::now();
+ logger.info("{}", sw);
+ auto val = std::stod(test_sink->lines()[0]);
+ auto diff_duration = duration_cast<std::chrono::duration<double>>(stop - start);
+
+ REQUIRE(val >= (diff_duration).count() - 0.001);
+ REQUIRE(val <= (diff_duration + tolerance_duration).count());
+}