1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
// 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 <benchmark/benchmark.h>
#include <boost/histogram/axis/regular.hpp>
#include <boost/histogram/storage_adaptor.hpp>
#include <memory>
#include "../test/histogram.hpp"
#include "../test/throw_exception.hpp"
#include "generator.hpp"
#include <cassert>
struct assert_check {
assert_check() {
assert(false); // don't run with asserts enabled
}
} _;
using SStore = std::vector<double>;
// make benchmark compatible with older versions of the library
#if __has_include(<boost/histogram/unlimited_storage.hpp>)
#include <boost/histogram/unlimited_storage.hpp>
using DStore = boost::histogram::unlimited_storage<>;
#else
#include <boost/histogram/adaptive_storage.hpp>
using DStore = boost::histogram::adaptive_storage<>;
#endif
using namespace boost::histogram;
namespace op = boost::histogram::axis::option;
using reg = axis::regular<>;
using reg_closed =
axis::regular<double, boost::use_default, boost::use_default, op::none_t>;
class reg_closed_unsafe {
public:
reg_closed_unsafe(axis::index_type n, double start, double stop)
: min_{start}, delta_{stop - start}, size_{n} {}
axis::index_type index(double x) const noexcept {
// Runs in hot loop, please measure impact of changes
auto z = (x - min_) / delta_;
// assume that z < 0 and z > 1 never happens, promised by inclusive()
if (z == 1) return size() - 1;
return static_cast<axis::index_type>(z * size());
}
axis::index_type size() const noexcept { return size_; }
static constexpr bool inclusive() { return true; }
private:
double min_;
double delta_;
axis::index_type size_;
};
template <class Distribution, class Tag, class Storage = SStore>
static void fill_1d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) benchmark::DoNotOptimize(h(gen()));
state.SetItemsProcessed(state.iterations());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_1d_closed(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg_closed(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) benchmark::DoNotOptimize(h(gen()));
state.SetItemsProcessed(state.iterations());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_1d_closed_unsafe(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg_closed_unsafe(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) benchmark::DoNotOptimize(h(gen()));
state.SetItemsProcessed(state.iterations());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_1d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) h.fill(gen);
state.SetItemsProcessed(state.iterations() * gen.size());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_1d_closed(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg_closed(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) h.fill(gen);
state.SetItemsProcessed(state.iterations() * gen.size());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_1d_closed_unsafe(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg_closed_unsafe(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) h.fill(gen);
state.SetItemsProcessed(state.iterations() * gen.size());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_2d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) benchmark::DoNotOptimize(h(gen(), gen()));
state.SetItemsProcessed(state.iterations() * 2);
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_2d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1));
auto gen = generator<Distribution>();
auto v = {gen, gen};
for (auto _ : state) h.fill(v);
state.SetItemsProcessed(state.iterations() * 2 * gen.size());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_3d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1), reg(100, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state) benchmark::DoNotOptimize(h(gen(), gen(), gen()));
state.SetItemsProcessed(state.iterations() * 3);
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_3d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(100, 0, 1), reg(100, 0, 1), reg(100, 0, 1));
auto gen = generator<Distribution>();
auto v = {gen, gen, gen};
for (auto _ : state) h.fill(v);
state.SetItemsProcessed(state.iterations() * 3 * gen.size());
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_6d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1),
reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1));
auto gen = generator<Distribution>();
for (auto _ : state)
benchmark::DoNotOptimize(h(gen(), gen(), gen(), gen(), gen(), gen()));
state.SetItemsProcessed(state.iterations() * 6);
}
template <class Distribution, class Tag, class Storage = SStore>
static void fill_n_6d(benchmark::State& state) {
auto h = make_s(Tag(), Storage(), reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1),
reg(10, 0, 1), reg(10, 0, 1), reg(10, 0, 1));
auto gen = generator<Distribution>();
auto v = {gen, gen, gen, gen, gen, gen};
for (auto _ : state) h.fill(v);
state.SetItemsProcessed(state.iterations() * 6 * gen.size());
}
BENCHMARK_TEMPLATE(fill_1d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_1d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_1d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_1d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_1d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_1d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_1d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_1d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_1d_closed, uniform, static_tag);
BENCHMARK_TEMPLATE(fill_1d_closed_unsafe, uniform, static_tag);
BENCHMARK_TEMPLATE(fill_n_1d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_n_1d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_1d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_n_1d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_1d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_1d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_1d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_1d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_1d_closed, uniform, static_tag);
BENCHMARK_TEMPLATE(fill_n_1d_closed_unsafe, uniform, static_tag);
BENCHMARK_TEMPLATE(fill_2d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_2d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_2d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_2d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_2d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_2d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_2d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_2d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_2d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_n_2d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_2d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_n_2d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_2d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_2d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_2d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_2d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_3d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_3d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_3d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_3d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_3d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_3d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_3d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_3d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_3d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_n_3d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_3d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_n_3d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_3d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_3d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_3d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_3d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_6d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_6d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_6d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_6d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_6d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_6d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_6d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_6d, normal, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_6d, uniform, static_tag);
// BENCHMARK_TEMPLATE(fill_n_6d, uniform, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_6d, normal, static_tag);
// BENCHMARK_TEMPLATE(fill_n_6d, normal, static_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_6d, uniform, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_6d, uniform, dynamic_tag, DStore);
BENCHMARK_TEMPLATE(fill_n_6d, normal, dynamic_tag);
// BENCHMARK_TEMPLATE(fill_n_6d, normal, dynamic_tag, DStore);
|