]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/histogram/benchmark/histogram_filling_gsl.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / histogram / benchmark / histogram_filling_gsl.cpp
CommitLineData
92f5a8d4
TL
1// Copyright 2015-2019 Hans Dembinski
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt
5// or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#include <benchmark/benchmark.h>
8#include <gsl/gsl_histogram.h>
9#include <gsl/gsl_histogram2d.h>
10#include "../test/throw_exception.hpp"
11#include "generator.hpp"
12
20effc67 13#include <cassert>
92f5a8d4
TL
14struct assert_check {
15 assert_check() {
20effc67 16 assert(false); // don't run with asserts enabled
92f5a8d4
TL
17 }
18} _;
19
20template <class Distribution>
21static void fill_1d(benchmark::State& state) {
22 gsl_histogram* h = gsl_histogram_alloc(100);
23 gsl_histogram_set_ranges_uniform(h, 0, 1);
24 generator<Distribution> gen;
25 for (auto _ : state) benchmark::DoNotOptimize(gsl_histogram_increment(h, gen()));
26 gsl_histogram_free(h);
27 state.SetItemsProcessed(state.iterations());
28}
29
30template <class Distribution>
31static void fill_2d(benchmark::State& state) {
32 gsl_histogram2d* h = gsl_histogram2d_alloc(100, 100);
33 gsl_histogram2d_set_ranges_uniform(h, 0, 1, 0, 1);
34 generator<Distribution> gen;
35 for (auto _ : state)
36 benchmark::DoNotOptimize(gsl_histogram2d_increment(h, gen(), gen()));
37 gsl_histogram2d_free(h);
38 state.SetItemsProcessed(state.iterations() * 2);
39}
40
41BENCHMARK_TEMPLATE(fill_1d, uniform);
42BENCHMARK_TEMPLATE(fill_2d, uniform);
43
44BENCHMARK_TEMPLATE(fill_1d, normal);
45BENCHMARK_TEMPLATE(fill_2d, normal);