1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
// (C) Copyright Nick Thompson 2020.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <vector>
#include <random>
#include <benchmark/benchmark.h>
#include <boost/math/special_functions/chebyshev.hpp>
template<class Real>
void ChebyshevClenshaw(benchmark::State& state)
{
std::vector<Real> v(state.range(0));
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_real_distribution<Real> unif(-1,1);
for (size_t i = 0; i < v.size(); ++i)
{
v[i] = unif(mt);
}
using boost::math::chebyshev_clenshaw_recurrence;
Real x = unif(mt);
for (auto _ : state)
{
benchmark::DoNotOptimize(chebyshev_clenshaw_recurrence(v.data(), v.size(), x));
}
state.SetComplexityN(state.range(0));
}
template<class Real>
void TranslatedChebyshevClenshaw(benchmark::State& state)
{
std::vector<Real> v(state.range(0));
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_real_distribution<Real> unif(-1,1);
for (size_t i = 0; i < v.size(); ++i)
{
v[i] = unif(mt);
}
using boost::math::detail::unchecked_chebyshev_clenshaw_recurrence;
Real x = unif(mt);
Real a = -2;
Real b = 5;
for (auto _ : state)
{
benchmark::DoNotOptimize(unchecked_chebyshev_clenshaw_recurrence(v.data(), v.size(), a, b, x));
}
state.SetComplexityN(state.range(0));
}
BENCHMARK_TEMPLATE(TranslatedChebyshevClenshaw, double)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity(benchmark::oN);
BENCHMARK_TEMPLATE(ChebyshevClenshaw, double)->RangeMultiplier(2)->Range(1<<1, 1<<22)->Complexity(benchmark::oN);
BENCHMARK_MAIN();
|