1 // Copyright 2015-2019 Hans Dembinski
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)
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"
13 #include <boost/assert.hpp>
16 BOOST_ASSERT(false); // don't run with asserts enabled
20 template <class Distribution>
21 static 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());
30 template <class Distribution>
31 static 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;
36 benchmark::DoNotOptimize(gsl_histogram2d_increment(h, gen(), gen()));
37 gsl_histogram2d_free(h);
38 state.SetItemsProcessed(state.iterations() * 2);
41 BENCHMARK_TEMPLATE(fill_1d, uniform);
42 BENCHMARK_TEMPLATE(fill_2d, uniform);
44 BENCHMARK_TEMPLATE(fill_1d, normal);
45 BENCHMARK_TEMPLATE(fill_2d, normal);