mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
axis benchmark and simpler circular index calculation
This commit is contained in:
parent
e8e85064b7
commit
5752fd8f87
@ -151,6 +151,7 @@ if (BUILD_BENCHMARKS)
|
||||
endfunction()
|
||||
|
||||
benchmark(test/iteration_bench.cpp)
|
||||
benchmark(test/axis_bench.cpp)
|
||||
|
||||
add_executable(speed_cpp test/speed_cpp.cpp)
|
||||
target_include_directories(speed_cpp PRIVATE include ${Boost_INCLUDE_DIR})
|
||||
|
@ -51,7 +51,7 @@ int main() {
|
||||
const auto b1 = x.bin(1); // current bin interval along second axis
|
||||
const auto v = *x; // "dereference" to get bin value
|
||||
os << boost::format("%i %i [%2i, %i) [%2i, %i): %i\n") % i % j % b0.lower() %
|
||||
b0.upper() % b1.lower() % b1.upper() % *x;
|
||||
b0.upper() % b1.lower() % b1.upper() % v;
|
||||
}
|
||||
|
||||
std::cout << os.str() << std::flush;
|
||||
|
@ -71,10 +71,8 @@ public:
|
||||
/// Returns the bin index for the passed argument.
|
||||
int operator()(value_type x) const noexcept {
|
||||
const auto z = std::floor((x - phase_) / delta_);
|
||||
if (std::isfinite(z)) {
|
||||
const auto i = static_cast<int>(z) % base_type::size();
|
||||
return i + (i < 0) * base_type::size();
|
||||
}
|
||||
if (std::isfinite(z))
|
||||
return static_cast<int>(z - std::floor(z / base_type::size()) * base_type::size());
|
||||
return base_type::size();
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,10 @@ struct null_type {};
|
||||
|
||||
enum class option_type {
|
||||
none = 0,
|
||||
underflow = 1,
|
||||
overflow = 2,
|
||||
uoflow = 3,
|
||||
underflow = 1 << 0,
|
||||
overflow = 1 << 1,
|
||||
uoflow = 1 << 2,
|
||||
circular = 1 << 3,
|
||||
};
|
||||
|
||||
constexpr inline option_type operator|(option_type a, option_type b) {
|
||||
|
95
test/axis_bench.cpp
Normal file
95
test/axis_bench.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
// 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 <boost/histogram/axis.hpp>
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
using namespace boost::histogram;
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void null(benchmark::State& state) {
|
||||
for (auto _ : state) {
|
||||
for (volatile int i = 0 - include_extra_bins; i < 10 + include_extra_bins; ++i);
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void regular(benchmark::State& state) {
|
||||
auto a = axis::regular<>(10, 0, 10);
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void circular(benchmark::State& state) {
|
||||
auto a = axis::circular<>(10, 0, 10);
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void integer_int(benchmark::State& state) {
|
||||
auto a = axis::integer<int>(0, 10);
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void integer_double(benchmark::State& state) {
|
||||
auto a = axis::integer<double>(0, 10);
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void variable(benchmark::State& state) {
|
||||
auto a = axis::variable<>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void category(benchmark::State& state) {
|
||||
auto a = axis::category<int>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool include_extra_bins>
|
||||
static void variant(benchmark::State& state) {
|
||||
auto a = axis::variant<axis::regular<>>(axis::regular<>(10, 0, 10));
|
||||
for (auto _ : state) {
|
||||
for (int i = 0 - include_extra_bins; i < a.size() + include_extra_bins; ++i)
|
||||
benchmark::DoNotOptimize(a(i));
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_TEMPLATE(null, false);
|
||||
BENCHMARK_TEMPLATE(null, true);
|
||||
BENCHMARK_TEMPLATE(regular, false);
|
||||
BENCHMARK_TEMPLATE(regular, true);
|
||||
BENCHMARK_TEMPLATE(circular, false);
|
||||
BENCHMARK_TEMPLATE(circular, true);
|
||||
BENCHMARK_TEMPLATE(integer_int, false);
|
||||
BENCHMARK_TEMPLATE(integer_int, true);
|
||||
BENCHMARK_TEMPLATE(integer_double, false);
|
||||
BENCHMARK_TEMPLATE(integer_double, true);
|
||||
BENCHMARK_TEMPLATE(variable, false);
|
||||
BENCHMARK_TEMPLATE(variable, true);
|
||||
BENCHMARK_TEMPLATE(category, false);
|
||||
BENCHMARK_TEMPLATE(category, true);
|
Loading…
x
Reference in New Issue
Block a user