From 810e84d60d74a788c9ec4fa9aba6d7bba76a8319 Mon Sep 17 00:00:00 2001 From: vindex10 Date: Fri, 30 Jul 2021 09:07:58 +0000 Subject: [PATCH] add test distributions mode benchmark --- .../performance/test_distributions_mode.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 reporting/performance/test_distributions_mode.cpp diff --git a/reporting/performance/test_distributions_mode.cpp b/reporting/performance/test_distributions_mode.cpp new file mode 100644 index 000000000..1bc4a77bf --- /dev/null +++ b/reporting/performance/test_distributions_mode.cpp @@ -0,0 +1,74 @@ +// (C) Copyright Victor Ananyev 2021. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + + +template class dist > +void test_mode_2param(benchmark::State& state) +{ + using boost::math::normal_distribution; + + std::random_device rd; + std::mt19937_64 mt(rd()); + std::normal_distribution noise(0., 1E-6); + + for (auto _ : state) + { + state.PauseTiming(); + Z p1 = state.range(0) + noise(mt); + Z p2 = state.range(1) + noise(mt); + dist the_dist(p1, p2); + state.ResumeTiming(); + try { + benchmark::DoNotOptimize(mode(the_dist)); + } + catch (boost::wrapexcept& e) { + state.SkipWithError(e.what()); + break; + } + } +} + + +template +static void fixed_ratio_2args(benchmark::internal::Benchmark* b, T left_div_right, std::vector lefts) { + for (const T &left: lefts) { + b->Args({(int64_t)left, (int64_t)(left/left_div_right)}); + } +} + + +using boost::math::non_central_chi_squared_distribution; + +BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)->ArgsProduct({ + {2, 15, 50}, + benchmark::CreateRange(4, 1024, /*multi=*/2) +})->Name("fixed_k"); + +BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution)->ArgsProduct({ + benchmark::CreateRange(4, 4096, /*multi=*/2), + {0, 30, 100, 500} +})->Name("fixed_nc"); + +BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution) + -> Apply([](benchmark::internal::Benchmark*b) { + fixed_ratio_2args(b, 0.05L, benchmark::CreateRange(4, 4096, /*multi=*/2)); + }) -> Name("fixed_scale_0_05"); + +BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution) + -> Apply([](benchmark::internal::Benchmark*b) { + fixed_ratio_2args(b, 0.15L, benchmark::CreateRange(4, 4096, /*multi=*/2)); + }) -> Name("fixed_scale_0_15"); + +BENCHMARK_TEMPLATE(test_mode_2param, long double, non_central_chi_squared_distribution) + -> Apply([](benchmark::internal::Benchmark*b) { + fixed_ratio_2args(b, 0.25L, benchmark::CreateRange(4, 4096, /*multi=*/2)); + }) -> Name("fixed_scale_0_25"); + +BENCHMARK_MAIN();