summaryrefslogtreecommitdiff
path: root/source/tests/bench.test.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-02 20:59:29 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-02 20:59:29 +0200
commit835e1fcd131c63ee2b3b647e327b33a3bfb369e3 (patch)
tree9d6fb42d6296a7bbec4a6ea58358c0fdb5de7e05 /source/tests/bench.test.c
parent34ba87d8c8cfef5ed249b34bd2d2b7e41a34d2f7 (diff)
downloadkit-835e1fcd131c63ee2b3b647e327b33a3bfb369e3.zip
[Linux] Change build system; Remove CMake
Diffstat (limited to 'source/tests/bench.test.c')
-rw-r--r--source/tests/bench.test.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/tests/bench.test.c b/source/tests/bench.test.c
new file mode 100644
index 0000000..92e216d
--- /dev/null
+++ b/source/tests/bench.test.c
@@ -0,0 +1,41 @@
+#define KIT_TEST_FILE bench
+#include "../kit_test/bench.h"
+
+struct test_foo_ {
+ double f;
+};
+
+BENCHMARK("foo") {
+
+ /* Benchmark setup.
+ */
+
+ BENCHMARK_BEGIN;
+ {
+ /* Measured code snippet.
+ */
+
+ int x = 0;
+ struct test_foo_ f = { 0. };
+
+ for (int i = 0; i < 100000; i++) {
+ x += (1 << 1);
+ x ^= i;
+ f.f += 0.1;
+ }
+
+ DO_NOT_OPTIMIZE(x);
+ DO_NOT_OPTIMIZE(f);
+ }
+ BENCHMARK_END;
+}
+
+BENCHMARK("bar") {
+ BENCHMARK_REPEAT(10);
+ BENCHMARK_REPEAT(100);
+
+ BENCHMARK_BEGIN;
+ BENCHMARK_END;
+}
+
+BENCHMARK("empty") { }