From 2dec5812f662d8c8f1973d8a0ba4e96dc7dfdb02 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 May 2025 16:49:01 +0000 Subject: [PATCH] dev qol: Add fn to make Stopwatch and start it at once --- src/lib_spark/spark/utils/stopwatch.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib_spark/spark/utils/stopwatch.h b/src/lib_spark/spark/utils/stopwatch.h index 06d614e94..43395f26f 100644 --- a/src/lib_spark/spark/utils/stopwatch.h +++ b/src/lib_spark/spark/utils/stopwatch.h @@ -18,6 +18,12 @@ struct Stopwatch { std::vector laps; bool is_running = false; + static Stopwatch start_new() { + Stopwatch sw; + sw.start(); + return sw; + } + core::TimeSpan elapsed() const { if (is_running) { return core::TimeStamp::now() - start_time; @@ -54,6 +60,12 @@ struct Stopwatch { start_time = core::TimeStamp::now(); } + void restart() { + is_running = false; + laps.clear(); + start(); + } + Stopwatch &lap() { if (is_running) { laps.emplace_back(start_time, core::TimeStamp::now());