]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/reporting/performance/cubic_roots_performance.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / reporting / performance / cubic_roots_performance.cpp
1 // (C) Copyright Nick Thompson 2021.
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 <array>
8 #include <vector>
9 #include <iostream>
10 #include <benchmark/benchmark.h>
11 #include <boost/math/tools/cubic_roots.hpp>
12
13 using boost::math::tools::cubic_roots;
14
15 template<class Real>
16 void CubicRoots(benchmark::State& state)
17 {
18 std::random_device rd;
19 auto seed = rd();
20 // This seed generates 3 real roots:
21 //uint32_t seed = 416683252;
22 std::mt19937_64 mt(seed);
23 std::uniform_real_distribution<Real> unif(-10, 10);
24
25 Real a = unif(mt);
26 Real b = unif(mt);
27 Real c = unif(mt);
28 Real d = unif(mt);
29 for (auto _ : state)
30 {
31 auto roots = cubic_roots(a,b,c,d);
32 benchmark::DoNotOptimize(roots[0]);
33 }
34 }
35
36 BENCHMARK_TEMPLATE(CubicRoots, float);
37 BENCHMARK_TEMPLATE(CubicRoots, double);
38 BENCHMARK_TEMPLATE(CubicRoots, long double);
39
40 BENCHMARK_MAIN();