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