]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // (C) Copyright Matt Borland 2022. |
2 | // Use, modification and distribution are subject to the | |
3 | // Boost Software License, Version 1.0. (See accompanying file | |
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #include <random> | |
7 | #include <limits> | |
8 | #include <benchmark/benchmark.h> | |
9 | #include <boost/math/special_functions/logaddexp.hpp> | |
10 | ||
11 | using boost::math::logaddexp; | |
12 | ||
13 | template <typename Real> | |
14 | void logaddexp_performance(benchmark::State& state) | |
15 | { | |
16 | std::random_device rd; | |
17 | std::mt19937_64 mt {rd()}; | |
18 | std::uniform_real_distribution<long double> dist(1e-50, 5e-50); | |
19 | ||
20 | Real x = static_cast<Real>(dist(mt)); | |
21 | Real y = static_cast<Real>(dist(mt)); | |
22 | ||
23 | for (auto _ : state) | |
24 | { | |
25 | benchmark::DoNotOptimize(logaddexp(x, y)); | |
26 | x += std::numeric_limits<Real>::epsilon(); | |
27 | y += std::numeric_limits<Real>::epsilon(); | |
28 | } | |
29 | } | |
30 | ||
31 | BENCHMARK_TEMPLATE(logaddexp_performance, float); | |
32 | BENCHMARK_TEMPLATE(logaddexp_performance, double); | |
33 | BENCHMARK_TEMPLATE(logaddexp_performance, long double); | |
34 | ||
35 | BENCHMARK_MAIN(); |