Skip to content

Commit

Permalink
Change parallelization crate from pariter to rayon
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderscoreTud committed Dec 7, 2024
1 parent 654931d commit ee8d7d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 66 deletions.
80 changes: 21 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ tinyjson = "2.5.1"

# Solution dependencies
itertools = "0.13.0"
pariter = "0.5.1"
rayon = "1.10.0"
regex = "1.11.1"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
| [Day 3](./src/bin/03.rs) | `561.0µs` | `565.5µs` |
| [Day 4](./src/bin/04.rs) | `560.8µs` | `161.9µs` |
| [Day 5](./src/bin/05.rs) | `344.6µs` | `323.6µs` |
| [Day 6](./src/bin/06.rs) | `499.6µs` | `160.3ms` |
| [Day 6](./src/bin/06.rs) | `492.2µs` | `118.9ms` |

**Total: 164.11ms**
**Total: 122.70ms**
<!--- benchmarking table --->

---
Expand Down
9 changes: 5 additions & 4 deletions src/bin/06.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rayon::iter::ParallelIterator;
use std::collections::HashSet;
use itertools::Itertools;
use pariter::{scope, IteratorExt};
use rayon::prelude::IntoParallelRefIterator;

advent_of_code::solution!(6);

Expand Down Expand Up @@ -112,8 +113,8 @@ pub fn part_two(input: &str) -> Option<u32> {
map.predict_path();
let mut original_path = map.visited_pos;
original_path.remove(&map.starting_pos);
Some(scope(|scope| original_path.iter()
.parallel_filter_scoped(scope, move |pos| {
Some(original_path.par_iter()
.filter(|pos| {
let mut new_obstacles = map.obstacles.clone();
new_obstacles.insert(**pos);
let mut map = Map {
Expand All @@ -123,7 +124,7 @@ pub fn part_two(input: &str) -> Option<u32> {
};
map.has_loop()
})
.count() as u32).unwrap())
.count() as u32)
}

#[cfg(test)]
Expand Down

0 comments on commit ee8d7d4

Please sign in to comment.