File: chebyshev_clenshaw.cpp

package info (click to toggle)
scipy 1.16.0-1exp7
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 234,820 kB
  • sloc: cpp: 503,145; python: 344,611; ansic: 195,638; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 848; makefile: 785; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (62 lines) | stat: -rw-r--r-- 1,790 bytes parent folder | download | duplicates (10)
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();