Skip to content

Commit

Permalink
2023 day 23: slightly improve part 2 performance
Browse files Browse the repository at this point in the history
I get a similar improvement by moving get_distance() into a lambda in
part_1().
  • Loading branch information
yut23 committed Feb 22, 2024
1 parent e6caa61 commit c864cfa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 2023/src/day23.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ void TrailMap::construct_trails(Pos start_pos) {
}
}

int TrailMap::get_distance(const Key from, const Key to) const {
// this attribute improves the performance of part_2() from 200ms to 175ms
// under clang
[[gnu::cold]] int TrailMap::get_distance(const Key from, const Key to) const {
// a linear search here is fine, since there are at most 4 neighbors, and
// only part 1 uses this function
for (const auto &[key, dist] : undirected_edges[from]) {
Expand Down

0 comments on commit c864cfa

Please sign in to comment.