Skip to content

Commit 3ed54de

Browse files
committed
bench(spline): Implemented benchmarks for PolyEqvSpline
1 parent c848eb9 commit 3ed54de

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

.idea/runConfigurations/bench_polyeqv.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benches/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ endmacro()
1515

1616
add_bench_executable(bench_poly poly/bench_poly.cpp)
1717
add_bench_executable(bench_barycentric misc/bench_barycentric.cpp)
18+
add_bench_executable(bench_polyeqv spline/bench_polyeqv.cpp)
1819
add_bench_executable(bench_step spline/bench_step.cpp)
1920
add_bench_executable(bench_linear spline/bench_linear.cpp)
2021
add_bench_executable(bench_quadratic spline/bench_quadratic.cpp)

benches/spline/bench_polyeqv.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <benchmark/benchmark.h>
2+
3+
#include <ALFI/spline/polyeqv.h>
4+
5+
#include "../bench_utils.h"
6+
#include "../bench_data.h"
7+
8+
const std::vector<alfi::spline::PolyEqvSpline<>::OptimizationType> polyeqv_spline_optimization_types = {
9+
alfi::spline::PolyEqvSpline<>::OptimizationType::ACCURACY,
10+
alfi::spline::PolyEqvSpline<>::OptimizationType::SPEED,
11+
};
12+
13+
static void BM_polyeqv_spline(benchmark::State& state) {
14+
const auto& [func_name, lambda] = funcs_and_ints[state.range(0)].first;
15+
const auto& interval = funcs_and_ints[state.range(0)].second;
16+
const auto& dist_type = dists[state.range(1)];
17+
const auto& n = state.range(2);
18+
const auto& optimization_type = polyeqv_spline_optimization_types[state.range(3)];
19+
const std::vector<double> X = of_type<double>(dist_type, n, interval.first, interval.second);
20+
const std::vector<double> Y = apply_func(X, lambda);
21+
alfi::spline::PolyEqvSpline<> spline;
22+
for (auto _ : state) {
23+
spline = alfi::spline::PolyEqvSpline<>(X, Y, alfi::spline::PolyEqvSpline<>::PolynomialType::LAGRANGE, optimization_type);
24+
benchmark::DoNotOptimize(spline);
25+
benchmark::ClobberMemory();
26+
}
27+
}
28+
BENCHMARK(BM_polyeqv_spline)
29+
->ArgsProduct({
30+
benchmark::CreateDenseRange(0, static_cast<int64_t>(funcs_and_ints.size()) - 1, 1),
31+
benchmark::CreateDenseRange(0, static_cast<int64_t>(dists.size()) - 1, 1),
32+
benchmark::CreateRange(8, 32, 2),
33+
benchmark::CreateDenseRange(0, static_cast<int64_t>(polyeqv_spline_optimization_types.size()) - 1, 1),
34+
})
35+
->ArgNames({"func", "dist", "n", "type"});
36+
37+
static void BM_polyeqv_spline_values(benchmark::State& state) {
38+
const auto& [func_name, lambda] = funcs_and_ints[state.range(0)].first;
39+
const auto& interval = funcs_and_ints[state.range(0)].second;
40+
const auto& dist_type = dists[state.range(1)];
41+
const auto& n = state.range(2);
42+
const auto& nn = state.range(3);
43+
const auto& optimization_type = polyeqv_spline_optimization_types[state.range(4)];
44+
const std::vector<double> X = of_type<double>(dist_type, n, interval.first, interval.second);
45+
const std::vector<double> Y = apply_func(X, lambda);
46+
const std::vector<double> xx = of_type<double>(alfi::dist::Type::UNIFORM, nn, interval.first, interval.second);
47+
const alfi::spline::PolyEqvSpline<> spline(X, Y, alfi::spline::PolyEqvSpline<>::PolynomialType::LAGRANGE, optimization_type);
48+
std::vector<double> result;
49+
for (auto _ : state) {
50+
result = spline.eval(xx);
51+
benchmark::DoNotOptimize(result);
52+
benchmark::ClobberMemory();
53+
}
54+
const std::vector<double> expected = apply_func(xx, lambda);
55+
add_error_metrics(state, result, expected);
56+
}
57+
BENCHMARK(BM_polyeqv_spline_values)
58+
->ArgsProduct({
59+
benchmark::CreateDenseRange(0, static_cast<int64_t>(funcs_and_ints.size()) - 1, 1),
60+
benchmark::CreateDenseRange(0, static_cast<int64_t>(dists.size()) - 1, 1),
61+
benchmark::CreateRange(8, 32, 2),
62+
{nn},
63+
benchmark::CreateDenseRange(0, static_cast<int64_t>(polyeqv_spline_optimization_types.size()) - 1, 1),
64+
})
65+
->ArgNames({"func", "dist", "n", "nn", "type"});
66+
67+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)