diff --git a/README.md b/README.md index a375430..c323832 100644 --- a/README.md +++ b/README.md @@ -72,5 +72,7 @@ algorithms in Rust and benchmark them. Let the battle begin. - `rayon sorted reverse`: Multi-threading provided by the `rayon` crate. Tasks are sorted so the longest ones are executed first. This should behave as an [LPT][lpt]. +- `rayon sorted reverse`: Similar to `rayon sorted reverse`, but tasks are + sorted from shortest to longest and are then iterated in the reverse order. [lpt]: https://en.wikipedia.org/wiki/Longest-processing-time-first_scheduling diff --git a/benches/job_scheduling.rs b/benches/job_scheduling.rs index 37184aa..8fb62c1 100644 --- a/benches/job_scheduling.rs +++ b/benches/job_scheduling.rs @@ -9,6 +9,7 @@ const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[ ("rayon", &rayon), ("rayon sorted", &rayon_sorted), ("rayon sorted reverse", &rayon_sorted_reverse), + ("rayon sorted reverse 2", &rayon_sorted_reverse_2), ]; fn job_scheduling_benchmark(c: &mut Criterion) { diff --git a/src/algorithm.rs b/src/algorithm.rs index 52541ff..f75d047 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -1,5 +1,5 @@ mod rayon; mod single_thread; -pub use rayon::{rayon, rayon_sorted, rayon_sorted_reverse}; +pub use rayon::*; pub use single_thread::single_thread; diff --git a/src/algorithm/rayon.rs b/src/algorithm/rayon.rs index da5ce73..fdac951 100644 --- a/src/algorithm/rayon.rs +++ b/src/algorithm/rayon.rs @@ -18,3 +18,9 @@ pub fn rayon_sorted_reverse(data: &[Task]) { data.sort_by(|a, b| a.cmp(b).reverse()); rayon(&data); } + +pub fn rayon_sorted_reverse_2(data: &[Task]) { + let mut data = data.to_vec(); + data.sort(); + data.into_par_iter().rev().for_each(|task| task.execute()); +}