Skip to content

Commit

Permalink
fix: bugprone-error
Browse files Browse the repository at this point in the history
Signed-off-by: kobayu858 <[email protected]>
  • Loading branch information
kobayu858 committed Dec 25, 2024
1 parent b764c57 commit 54372cc
Showing 1 changed file with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,43 +57,52 @@ int main()
{
Obstacles obstacles;
std::vector<polygon_t> polygons;

Check failure on line 59 in planning/motion_velocity_planner/autoware_motion_velocity_obstacle_velocity_limiter_module/benchmarks/collision_checker_benchmark.cpp

View workflow job for this annotation

GitHub Actions / cppcheck-differential

The scope of the variable 'polygons' can be reduced. [variableScope]
polygons.reserve(100);
for (auto i = 0; i < 100; ++i) {
polygons.push_back(random_polygon());
}
for (auto nb_lines = 1lu; nb_lines < 1000lu; nb_lines += 10) {
obstacles.lines.push_back(random_line());
obstacles.points.clear();
for (auto nb_points = 1lu; nb_points < 1000lu; nb_points += 10) {
obstacles.points.push_back(random_point());
const auto rtt_constr_start = std::chrono::system_clock::now();
CollisionChecker rtree_collision_checker(obstacles, 0, 0);
const auto rtt_constr_end = std::chrono::system_clock::now();
const auto naive_constr_start = std::chrono::system_clock::now();
CollisionChecker naive_collision_checker(obstacles, nb_points + 1, nb_lines * 100);
const auto naive_constr_end = std::chrono::system_clock::now();
const auto rtt_check_start = std::chrono::system_clock::now();
for (const auto & polygon : polygons)
// cppcheck-suppress unreadVariable
const auto rtree_result = rtree_collision_checker.intersections(polygon);
const auto rtt_check_end = std::chrono::system_clock::now();
const auto naive_check_start = std::chrono::system_clock::now();
for (const auto & polygon : polygons)
// cppcheck-suppress unreadVariable
const auto naive_result = naive_collision_checker.intersections(polygon);
const auto naive_check_end = std::chrono::system_clock::now();
const auto rtt_constr_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(rtt_constr_end - rtt_constr_start);
const auto naive_constr_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(naive_constr_end - naive_constr_start);
const auto rtt_check_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(rtt_check_end - rtt_check_start);
const auto naive_check_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(naive_check_end - naive_check_start);
std::printf(
"%lu, %lu, %ld, %ld, %ld, %ld\n", nb_lines, nb_points, rtt_constr_time.count(),
rtt_check_time.count(), naive_constr_time.count(), naive_check_time.count());

try {
polygons.reserve(100);
for (auto i = 0; i < 100; ++i) {
polygons.push_back(random_polygon());
}
for (auto nb_lines = 1lu; nb_lines < 1000lu; nb_lines += 10) {
obstacles.lines.push_back(random_line());
obstacles.points.clear();
for (auto nb_points = 1lu; nb_points < 1000lu; nb_points += 10) {
obstacles.points.push_back(random_point());
const auto rtt_constr_start = std::chrono::system_clock::now();
CollisionChecker rtree_collision_checker(obstacles, 0, 0);
const auto rtt_constr_end = std::chrono::system_clock::now();
const auto naive_constr_start = std::chrono::system_clock::now();
CollisionChecker naive_collision_checker(obstacles, nb_points + 1, nb_lines * 100);
const auto naive_constr_end = std::chrono::system_clock::now();
const auto rtt_check_start = std::chrono::system_clock::now();
for (const auto & polygon : polygons)
// cppcheck-suppress unreadVariable
const auto rtree_result = rtree_collision_checker.intersections(polygon);
const auto rtt_check_end = std::chrono::system_clock::now();
const auto naive_check_start = std::chrono::system_clock::now();
for (const auto & polygon : polygons)
// cppcheck-suppress unreadVariable
const auto naive_result = naive_collision_checker.intersections(polygon);
const auto naive_check_end = std::chrono::system_clock::now();
const auto rtt_constr_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(rtt_constr_end - rtt_constr_start);
const auto naive_constr_time = std::chrono::duration_cast<std::chrono::nanoseconds>(
naive_constr_end - naive_constr_start);
const auto rtt_check_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(rtt_check_end - rtt_check_start);
const auto naive_check_time =
std::chrono::duration_cast<std::chrono::nanoseconds>(naive_check_end - naive_check_start);
std::printf(
"%lu, %lu, %ld, %ld, %ld, %ld\n", nb_lines, nb_points, rtt_constr_time.count(),
rtt_check_time.count(), naive_constr_time.count(), naive_check_time.count());
}
}
} catch (const std::exception & e) {
std::cerr << "Exception in main(): " << e.what() << std::endl;
return {};
} catch (...) {
std::cerr << "Unknown exception in main()" << std::endl;
return {};
}
return 0;
}

0 comments on commit 54372cc

Please sign in to comment.