File: axis_index.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (77 lines) | stat: -rw-r--r-- 2,531 bytes parent folder | download | duplicates (11)
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
// Copyright 2018 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.hpp>
#include <numeric>
#include "../test/throw_exception.hpp"
#include "generator.hpp"

#include <cassert>
struct assert_check {
  assert_check() {
    assert(false); // don't run with asserts enabled
  }
} _;

using namespace boost::histogram;

template <class Distribution>
static void regular(benchmark::State& state) {
  auto a = axis::regular<>(100, 0.0, 1.0);
  generator<Distribution> gen;
  for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

template <class Distribution>
static void circular(benchmark::State& state) {
  auto a = axis::circular<>(100, 0.0, 1.0);
  generator<Distribution> gen;
  for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

template <class T, class Distribution>
static void integer(benchmark::State& state) {
  auto a = axis::integer<T>(0, 1);
  generator<Distribution> gen;
  for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

template <class Distribution>
static void variable(benchmark::State& state) {
  std::vector<double> v;
  for (double x = 0; x <= state.range(0); ++x) { v.push_back(x / state.range(0)); }
  auto a = axis::variable<>(v);
  generator<Distribution> gen;
  for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

static void category(benchmark::State& state) {
  std::vector<int> v(state.range(0));
  std::iota(v.begin(), v.end(), 0);
  auto a = axis::category<int>(v);
  generator<uniform_int> gen(static_cast<int>(state.range(0)));
  for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

static void boolean(benchmark::State& state) {
  auto a = axis::boolean<>();
  generator<uniform_int> gen(1);
  for (auto _ : state) benchmark::DoNotOptimize(a.index(static_cast<bool>(gen())));
}

BENCHMARK_TEMPLATE(regular, uniform);
BENCHMARK_TEMPLATE(regular, normal);
BENCHMARK_TEMPLATE(circular, uniform);
BENCHMARK_TEMPLATE(circular, normal);
BENCHMARK_TEMPLATE(integer, int, uniform);
BENCHMARK_TEMPLATE(integer, int, normal);
BENCHMARK_TEMPLATE(integer, double, uniform);
BENCHMARK_TEMPLATE(integer, double, normal);
BENCHMARK_TEMPLATE(variable, uniform)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK_TEMPLATE(variable, normal)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK(category)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK(boolean);