15 #include <benchmark/benchmark.h>
20 #include <type_traits>
22 #include <range/v3/algorithm/copy.hpp>
23 #include <range/v3/range/access.hpp>
24 #include <range/v3/range/primitives.hpp>
25 #include <range/v3/view/subrange.hpp>
26 #include <range/v3/view/take_exactly.hpp>
47 const auto tuple = std::make_tuple(
state.x,
state.y);
55 using Particle =
typename Container::value_type;
57 void BM_FixedResample(benchmark::State&
state) {
58 const auto particle_count =
state.range(0);
59 state.SetComplexityN(particle_count);
60 const auto container_size =
static_cast<std::size_t
>(particle_count);
62 auto container = Container{container_size};
63 auto new_container = Container{container_size};
69 for (
auto _ :
state) {
70 auto samples = container |
72 ranges::views::take_exactly(container_size);
73 auto first = ranges::begin(new_container);
74 auto last = ranges::copy(samples, first).out;
75 auto result = ranges::make_subrange(first, last);
76 state.counters[
"SampleSize"] =
static_cast<double>(ranges::size(result));
80 BENCHMARK(BM_FixedResample)->RangeMultiplier(2)->Range(128, 1
'000'000)->Complexity();
82 void BM_AdaptiveResample(benchmark::State&
state) {
83 const auto particle_count =
state.range(0);
84 state.SetComplexityN(particle_count);
85 const auto container_size =
static_cast<std::size_t
>(particle_count);
87 auto container = Container{container_size};
88 auto new_container = Container{container_size};
100 const std::size_t min_samples = 0;
101 const std::size_t max_samples = container_size;
102 const double kld_epsilon = 0.05;
103 const double kld_z = 3.;
105 for (
auto _ :
state) {
110 auto first = ranges::begin(new_container);
111 auto last = ranges::copy(samples, first).out;
112 auto result = ranges::make_subrange(first, last);
113 state.counters[
"SampleSize"] =
static_cast<double>(ranges::size(result));
114 state.counters[
"Percentage"] =
static_cast<double>(ranges::size(result)) /
static_cast<double>(max_samples);
118 BENCHMARK(BM_AdaptiveResample)->RangeMultiplier(2)->Range(128, 1
'000'000)->Complexity();