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)
8 #include <boost/math/distributions.hpp>
9 #include <benchmark/benchmark.h>
12 template <class Z
, template<typename
> class dist
>
13 void test_mode_2param(benchmark::State
& state
)
15 using boost::math::normal_distribution
;
17 std::random_device rd
;
18 std::mt19937_64
mt(rd());
19 std::normal_distribution
<Z
> noise(0., 1E-6);
24 Z p1
= state
.range(0) + noise(mt
);
25 Z p2
= state
.range(1) + noise(mt
);
26 dist
<Z
> the_dist(p1
, p2
);
29 benchmark::DoNotOptimize(mode(the_dist
));
31 catch (boost::wrapexcept
<boost::math::evaluation_error
>& e
) {
32 state
.SkipWithError(e
.what());
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
))});
46 using boost::math::non_central_chi_squared_distribution
;
48 BENCHMARK_TEMPLATE(test_mode_2param
, long double, non_central_chi_squared_distribution
)->ArgsProduct({
50 benchmark::CreateRange(4, 1024, /*multi=*/2)
53 BENCHMARK_TEMPLATE(test_mode_2param
, long double, non_central_chi_squared_distribution
)->ArgsProduct({
54 benchmark::CreateRange(4, 4096, /*multi=*/2),
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");
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");
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");