56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
#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
|