summaryrefslogtreecommitdiffhomepage
path: root/test/bench.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/bench.hpp')
-rw-r--r--test/bench.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/bench.hpp b/test/bench.hpp
new file mode 100644
index 00000000..7101e49f
--- /dev/null
+++ b/test/bench.hpp
@@ -0,0 +1,27 @@
+#pragma once
+#include <chrono>
+#include <Corrade/Containers/StringView.h>
+
+namespace floormat {
+
+template<typename F>
+requires requires (F& fun) { fun(); }
+void bench_run(StringView name, F&& fun)
+{
+ using namespace std::chrono;
+ using clock = high_resolution_clock;
+#if 0
+ for (int i = 0; i < 20; i++)
+ fun();
+ const auto t0 = clock::now();
+ for (int i = 0; i < 1000; i++)
+ fun();
+#else
+ const auto t0 = clock::now();
+ fun();
+#endif
+ const auto tm = clock::now() - t0;
+ Debug{} << "test" << name << "took" << duration_cast<milliseconds>(tm).count() << "ms.";
+}
+
+} // namespace floormat