summaryrefslogtreecommitdiff
path: root/src/utils/scopetimer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/scopetimer.hpp')
-rw-r--r--src/utils/scopetimer.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/scopetimer.hpp b/src/utils/scopetimer.hpp
new file mode 100644
index 0000000..7d3db9b
--- /dev/null
+++ b/src/utils/scopetimer.hpp
@@ -0,0 +1,17 @@
+#include <utils/scopeguard.hpp>
+
+#include <chrono>
+
+#include <logger/logger.hpp>
+
+template <typename Callback>
+auto make_scope_timer(Callback cb)
+{
+ const auto start_time = std::chrono::steady_clock::now();
+ return utils::make_scope_guard([start_time, cb = std::move(cb)]()
+ {
+ const auto now = std::chrono::steady_clock::now();
+ const auto elapsed = now - start_time;
+ cb(elapsed);
+ });
+}