test: benchmark between libs
This commit is contained in:
parent
6e0a576b2c
commit
0c5f5aa464
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -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)
|
||||
7
tests/CMakeLists.txt
Normal file
7
tests/CMakeLists.txt
Normal file
@ -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)
|
||||
55
tests/pipeline.test.cpp
Normal file
55
tests/pipeline.test.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include <pipeline/pipeline.hpp>
|
||||
#include <pipes/pipes.hpp>
|
||||
#include <vector>
|
||||
|
||||
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<int> ans;
|
||||
|
||||
mux(std::vector<int>{0}, std::vector<int>{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
|
||||
Loading…
x
Reference in New Issue
Block a user