test
benchmark
benchmark_likelihood_field_model.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 <cstddef>
18
#include <utility>
19
#include <vector>
20
21
#include <Eigen/Core>
22
23
#include <
sophus/se2.hpp
>
24
#include <
sophus/so2.hpp
>
25
26
namespace
{
27
28
constexpr std::size_t kNumParticles = 2
'000;
29
30
void BM_PointTransform_Baseline(benchmark::State& state) {
31
const auto count = state.range(0);
32
state.SetComplexityN(count);
33
auto size = static_cast<size_t>(count);
34
const auto particles = std::vector<Sophus::SE2d>{kNumParticles};
35
const auto points = std::vector<std::pair<double, double>>(size);
36
const auto origin = Sophus::SE2d{};
37
for (auto _ : state) {
38
for (const auto& pose : particles) {
39
const auto transform = origin * pose;
40
const double x_offset = transform.translation().x();
41
const double y_offset = transform.translation().y();
42
const double cos_theta = transform.so2().unit_complex().x();
43
const double sin_theta = transform.so2().unit_complex().y();
44
for (const auto& point : points) {
45
const auto x = point.first * cos_theta - point.second * sin_theta + x_offset;
46
const auto y = point.first * sin_theta + point.second * cos_theta + y_offset;
47
benchmark::DoNotOptimize(x + y);
48
}
49
}
50
}
51
}
52
53
void BM_PointTransform_EigenSophus(benchmark::State& state) {
54
const auto count = state.range(0);
55
state.SetComplexityN(count);
56
auto size = static_cast<size_t>(count);
57
const auto particles = std::vector<Sophus::SE2d>{kNumParticles};
58
const auto points = std::vector<Eigen::Vector2d>(size);
59
const auto origin = Sophus::SE2d{};
60
for (auto _ : state) {
61
for (const auto& pose : particles) {
62
const auto transform = origin * pose;
63
for (const auto& point : points) {
64
const auto result = transform * point;
65
const auto x = result.x();
66
const auto y = result.y();
67
benchmark::DoNotOptimize(x + y);
68
}
69
}
70
}
71
}
72
73
BENCHMARK(BM_PointTransform_Baseline)->RangeMultiplier(2)->Range(128, 1024)->Complexity();
74
BENCHMARK(BM_PointTransform_EigenSophus)->RangeMultiplier(2)->Range(128, 1024)->Complexity();
75
76
} // namespace
se2.hpp
so2.hpp
beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53