From 0c5f5aa464d5ba2a13a3b40aa605b89fc5940e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Murta?= Date: Fri, 1 Aug 2025 20:07:31 +0100 Subject: [PATCH] test: benchmark between libs --- CMakeLists.txt | 13 ++++++++++ tests/CMakeLists.txt | 7 ++++++ tests/pipeline.test.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/pipeline.test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a147ad7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.20) +project( + pipeline_asio + VERSION 0.1.0 + LANGUAGES CXX) + +# dependencies +find_package(fmt REQUIRED) +add_subdirectory(external/pipeline) +add_subdirectory(external/pipes) + +enable_testing() +add_subdirectory(tests) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..62377b6 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(benchmark REQUIRED) + +add_executable(pipeline.test pipeline.test.cpp) +target_compile_features(pipeline.test PUBLIC cxx_std_23) +target_link_libraries(pipeline.test benchmark::benchmark_main + pipeline::pipeline joboccara::pipes) +add_test(NAME pipeline.test COMMAND pipeline.test) diff --git a/tests/pipeline.test.cpp b/tests/pipeline.test.cpp new file mode 100644 index 0000000..b5b53a4 --- /dev/null +++ b/tests/pipeline.test.cpp @@ -0,0 +1,55 @@ +#include + +#include +#include +#include + +namespace { + +void BM_Pipeline(benchmark::State& state) { + using namespace pipeline; + + for (auto _ : state) { + auto add = fn([](auto a, auto b) { return a + b; }); + auto double_it = fn([](auto a) { return a * 2; }); + auto square_it = fn([](auto a) { return a * a; }); + auto pipeline = add | double_it | square_it; + + auto ans = pipeline(0, 1); + benchmark::DoNotOptimize(ans); + } +} +BENCHMARK(BM_Pipeline); + +void BM_Pipes(benchmark::State& state) { + using namespace pipes; + + for (auto _ : state) { + std::vector ans; + + mux(std::vector{0}, std::vector{1}) >>= + transform([](int a, int b) { return a + b; }) >>= + transform([](int a) { return a * 2; }) >>= + transform([](int a) { return a * a; }) >>= push_back(ans); + + benchmark::DoNotOptimize(ans); + } +} +BENCHMARK(BM_Pipes); + +} // namespace + +// 2025-07-31T22:57:54+01:00 +// Running /home/murta/src/pipeline/build/tests/pipeline.test +// Run on (16 X 3200 MHz CPU s) +// CPU Caches: +// L1 Data 32 KiB (x8) +// L1 Instruction 64 KiB (x8) +// L2 Unified 512 KiB (x8) +// L3 Unified 8192 KiB (x2) +// Load Average: 0.42, 0.47, 0.40 +// ------------------------------------------------------ +// Benchmark Time CPU Iterations +// ------------------------------------------------------ +// BM_Pipeline 0.340 ns 0.340 ns 2065571679 +// BM_Pipes 13.3 ns 13.3 ns 54185576