From 2097c0fe36e994a43608c58b00a04878d09a7a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Mon, 2 Oct 2023 12:58:12 +0200 Subject: [PATCH] add instrumentation for runtime measurement --- timer.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 timer.hpp diff --git a/timer.hpp b/timer.hpp new file mode 100644 index 0000000..5e7d1d7 --- /dev/null +++ b/timer.hpp @@ -0,0 +1,22 @@ +#ifndef TIMER_H_ +#define TIMER_H_ + +#include +#include +#include + +template +struct measure { + template + static auto duration(F &&func, Args &&...args) { + auto start = ClockType::now(); + auto retVal = + std::invoke(std::forward(func), std::forward(args)...); + auto end = ClockType::now(); + return std::make_pair(retVal, + std::chrono::duration_cast(end - start)); + } +}; + +#endif // TIMER_H_