]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/reporting/performance/test_distributions_mode.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / reporting / performance / test_distributions_mode.cpp
1 // (C) Copyright Victor Ananyev 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 <vector>
8 #include <boost/math/distributions.hpp>
9 #include <benchmark/benchmark.h>
10
11
12 template <class Z, template<typename> class dist >
13 void test_mode_2param(benchmark::State& state)
14 {
15 using boost::math::normal_distribution;
16
17 std::random_device rd;
18 std::mt19937_64 mt(rd());
19 std::normal_distribution<Z> noise(0., 1E-6);
20
21 for (auto _ : state)
22 {
23 state.PauseTiming();
24 Z p1 = state.range(0) + noise(mt);
25 Z p2 = state.range(1) + noise(mt);
26 dist<Z> the_dist(p1, p2);
27 state.ResumeTiming();
28 try {
29 benchmark::DoNotOptimize(mode(the_dist));
30 }
31 catch (boost::wrapexcept<boost::math::evaluation_error>& e) {
32 state.SkipWithError(e.what());
33 break;
34 }
35 }
36 }
37
38
39 static void fixed_ratio_2args(benchmark::internal::Benchmark* b, long double left_div_right, std::vector<int64_t> lefts) {
40 for (const long double &left: lefts) {
41 b->Args({static_cast<int64_t>(left), static_cast<int64_t>((left/left_div_right))});
42 }
43 }
44
45
46 using boost::math::non_central_chi_squared_distribution;
47
48 BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)->ArgsProduct({
49 {2, 15, 50},
50 benchmark::CreateRange(4, 1024, /*multi=*/2)
51 })->Name("fixed_k");
52
53 BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)->ArgsProduct({
54 benchmark::CreateRange(4, 4096, /*multi=*/2),
55 {1, 30, 100, 500}
56 })->Name("fixed_nc");
57
58 BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)
59 -> Apply([](benchmark::internal::Benchmark*b) {
60 fixed_ratio_2args(b, 0.05, benchmark::CreateRange(4, 4096, /*multi=*/2));
61 }) -> Name("fixed_scale_0_05");
62
63 BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)
64 -> Apply([](benchmark::internal::Benchmark*b) {
65 fixed_ratio_2args(b, 0.15, benchmark::CreateRange(4, 4096, /*multi=*/2));
66 }) -> Name("fixed_scale_0_15");
67
68 BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)
69 -> Apply([](benchmark::internal::Benchmark*b) {
70 fixed_ratio_2args(b, 0.25, benchmark::CreateRange(4, 4096, /*multi=*/2));
71 }) -> Name("fixed_scale_0_25");
72
73 BENCHMARK_MAIN();