]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // (C) Copyright Nick Thompson 2020. |
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 <benchmark/benchmark.h> | |
8 | #include <boost/math/special_functions/rsqrt.hpp> | |
9 | #include <boost/multiprecision/float128.hpp> | |
10 | #include <boost/multiprecision/mpfr.hpp> | |
11 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
12 | ||
13 | using boost::multiprecision::number; | |
14 | using boost::multiprecision::mpfr_float_backend; | |
15 | using boost::multiprecision::float128; | |
16 | using boost::multiprecision::cpp_bin_float_50; | |
17 | using boost::multiprecision::cpp_bin_float_100; | |
18 | using boost::math::rsqrt; | |
19 | ||
20 | template<class Real> | |
21 | void Rsqrt(benchmark::State& state) | |
22 | { | |
23 | std::random_device rd; | |
24 | std::mt19937_64 mt(rd()); | |
25 | std::uniform_real_distribution<long double> unif(1,100); | |
26 | ||
27 | Real x = static_cast<Real>(unif(mt)); | |
28 | for (auto _ : state) | |
29 | { | |
30 | benchmark::DoNotOptimize(rsqrt(x)); | |
31 | x += std::numeric_limits<Real>::epsilon(); | |
32 | } | |
33 | } | |
34 | ||
35 | BENCHMARK_TEMPLATE(Rsqrt, float); | |
36 | BENCHMARK_TEMPLATE(Rsqrt, double); | |
37 | BENCHMARK_TEMPLATE(Rsqrt, long double); | |
38 | BENCHMARK_TEMPLATE(Rsqrt, float128); | |
39 | BENCHMARK_TEMPLATE(Rsqrt, number<mpfr_float_backend<100>>); | |
40 | BENCHMARK_TEMPLATE(Rsqrt, number<mpfr_float_backend<200>>); | |
41 | BENCHMARK_TEMPLATE(Rsqrt, number<mpfr_float_backend<300>>); | |
42 | BENCHMARK_TEMPLATE(Rsqrt, number<mpfr_float_backend<400>>); | |
43 | BENCHMARK_TEMPLATE(Rsqrt, number<mpfr_float_backend<1000>>); | |
44 | BENCHMARK_TEMPLATE(Rsqrt, cpp_bin_float_50); | |
45 | BENCHMARK_TEMPLATE(Rsqrt, cpp_bin_float_100); | |
46 | ||
47 | BENCHMARK_MAIN(); |