// Copyright 2015-2019 Hans Dembinski // // Distributed under 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 #include #include #include #include #include "../test/throw_exception.hpp" #include "generator.hpp" #include struct assert_check { assert_check() { BOOST_ASSERT(false); // don't run with asserts enabled } } _; using namespace boost::histogram; using reg = axis::regular<>; using integ = axis::integer<>; using var = axis::variable<>; using vector_of_variant = std::vector>; template auto make_storage(const U& axes) { return std::vector(detail::bincount(axes), 0); } template void fill_a(const Axes& axes, Storage& storage, const Tuple& t) { using namespace boost::mp11; std::size_t stride = 1, index = 0; mp_for_each>>([&](auto i) { const auto& a = boost::histogram::detail::axis_get(axes); const auto& v = std::get(t); index += (a.index(v) + 1) * stride; stride *= axis::traits::extent(a); }); ++storage[index]; } template static void fill_1d_a(benchmark::State& state) { auto axes = std::make_tuple(reg(100, 0, 1)); generator gen; auto storage = make_storage(axes); for (auto _ : state) fill_a(axes, storage, std::forward_as_tuple(gen())); state.SetItemsProcessed(state.iterations()); } template static void fill_1d_a_dyn(benchmark::State& state) { auto axes = vector_of_variant({reg(100, 0, 1)}); generator gen; auto storage = make_storage(axes); for (auto _ : state) fill_a(axes, storage, std::forward_as_tuple(gen())); state.SetItemsProcessed(state.iterations()); } template static void fill_2d_a(benchmark::State& state) { auto axes = std::make_tuple(reg(100, 0, 1), reg(100, 0, 1)); generator gen; auto storage = make_storage(axes); for (auto _ : state) fill_a(axes, storage, std::forward_as_tuple(gen(), gen())); state.SetItemsProcessed(state.iterations() * 2); } template static void fill_2d_a_dyn(benchmark::State& state) { auto axes = vector_of_variant({reg(100, 0, 1), reg(100, 0, 1)}); generator gen; auto storage = make_storage(axes); for (auto _ : state) fill_a(axes, storage, std::forward_as_tuple(gen(), gen())); state.SetItemsProcessed(state.iterations() * 2); } BENCHMARK_TEMPLATE(fill_1d_a, double, uniform); BENCHMARK_TEMPLATE(fill_1d_a_dyn, double, uniform); BENCHMARK_TEMPLATE(fill_2d_a, double, uniform); BENCHMARK_TEMPLATE(fill_2d_a_dyn, double, uniform); BENCHMARK_TEMPLATE(fill_1d_a, double, normal); BENCHMARK_TEMPLATE(fill_2d_a, double, normal);