benchmark_spatial_hash.cpp
Go to the documentation of this file.
1 // Copyright 2022-2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <benchmark/benchmark.h>
16 
17 #include <array>
18 #include <cstddef>
19 #include <iterator>
20 #include <tuple>
21 
22 #include <range/v3/view/generate.hpp>
23 #include <range/v3/view/take_exactly.hpp>
24 #include <range/v3/view/transform.hpp>
25 
27 
28 namespace {
29 
30 void BM_Hashing(benchmark::State& state) {
31  using Tuple = std::tuple<double, double, double>;
32  constexpr std::array kClusteringResolution{1., 1., 1.};
33  auto hasher = beluga::spatial_hash<Tuple>{kClusteringResolution};
34 
35  const auto count = state.range(0);
36  state.SetComplexityN(count);
37 
38  for (auto _ : state) {
39  auto hashes = ranges::views::generate([]() { return std::make_tuple(1., 2., 3.); }) |
40  ranges::views::transform([hasher](const auto& tuple) { return hasher(tuple); }) |
41  ranges::views::take_exactly(count);
42 
43  auto first = std::begin(hashes);
44  auto last = std::end(hashes);
45  std::size_t value;
46  while (first != last) {
47  benchmark::DoNotOptimize(value = *first++);
48  }
49  }
50 }
51 
52 BENCHMARK(BM_Hashing)->RangeMultiplier(2)->Range(100'000, 1'000'000)->Complexity();
53 
54 } // namespace
beluga::state
constexpr state_detail::state_fn state
Customization point object for accessing the state of a particle.
Definition: primitives.hpp:163
beluga::spatial_hash
Callable class, allowing to calculate the hash of a particle state.
Definition: spatial_hash.hpp:100
spatial_hash.hpp
Implementation of a spatial hash for N dimensional states.


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53