From ce20101ecb912b294b208e6e59b4a7f9214370c3 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sat, 25 Mar 2023 08:38:16 +0100 Subject: Microbenchmarks --- source/test/unittests/CMakeLists.txt | 9 +++++---- source/test/unittests/foo.bench.c | 13 +++++++++++++ source/test/unittests/main.test.c | 6 +++++- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 source/test/unittests/foo.bench.c (limited to 'source/test/unittests') diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt index a73ca6e..b8a6dca 100644 --- a/source/test/unittests/CMakeLists.txt +++ b/source/test/unittests/CMakeLists.txt @@ -2,7 +2,8 @@ target_sources( kit_test_suite PRIVATE async_function.test.c bigint.test.c mutex.test.c - test_duration.test.c main.test.c string_ref.test.c atomic.test.c thread.test.c - array_ref.test.c input_stream.test.c sha256.test.c lower_bound.test.c - secure_random.test.c condition_variable.test.c mersenne_twister_64.test.c - input_buffer.test.c move_back.test.c dynamic_array.test.c file.test.c) + test_duration.test.c main.test.c string_ref.test.c atomic.test.c foo.bench.c + thread.test.c array_ref.test.c input_stream.test.c sha256.test.c + lower_bound.test.c secure_random.test.c condition_variable.test.c + mersenne_twister_64.test.c input_buffer.test.c move_back.test.c dynamic_array.test.c + file.test.c) diff --git a/source/test/unittests/foo.bench.c b/source/test/unittests/foo.bench.c new file mode 100644 index 0000000..531f1d8 --- /dev/null +++ b/source/test/unittests/foo.bench.c @@ -0,0 +1,13 @@ +#define KIT_BENCH_FILE foo +#include "../../kit_test/bench.h" + +BENCHMARK("foo") { + BENCHMARK_BEGIN; + { + volatile int x = 0; + for (int i = 0; i < 200000; i++) x++; + } + BENCHMARK_END; +} + +BENCHMARK("bar") { } diff --git a/source/test/unittests/main.test.c b/source/test/unittests/main.test.c index 3ced74c..60c2e36 100644 --- a/source/test/unittests/main.test.c +++ b/source/test/unittests/main.test.c @@ -1,5 +1,9 @@ +#include "../../kit_test/bench.h" #include "../../kit_test/test.h" int main(int argc, char **argv) { - return run_tests(argc, argv); + int status = run_tests(argc, argv); + if (status == 0) + status = run_benchmarks(argc, argv); + return status; } -- cgit v1.2.3