From 501179f5fd480796b96e5ad6ed4a7c725fffa343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Wed, 30 Oct 2024 22:23:55 +0100 Subject: [PATCH] Add the rayon_sorted_reverse algorithm --- benches/job_scheduling.rs | 1 + src/algorithm/rayon.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/benches/job_scheduling.rs b/benches/job_scheduling.rs index d0c619f..37184aa 100644 --- a/benches/job_scheduling.rs +++ b/benches/job_scheduling.rs @@ -8,6 +8,7 @@ const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[ ("single thread", &single_thread), ("rayon", &rayon), ("rayon sorted", &rayon_sorted), + ("rayon sorted reverse", &rayon_sorted_reverse), ]; fn job_scheduling_benchmark(c: &mut Criterion) { diff --git a/src/algorithm/rayon.rs b/src/algorithm/rayon.rs index 0fad83b..da5ce73 100644 --- a/src/algorithm/rayon.rs +++ b/src/algorithm/rayon.rs @@ -7,6 +7,14 @@ pub fn rayon(data: &[Task]) { pub fn rayon_sorted(data: &[Task]) { let mut data = data.to_vec(); + // Shortest tasks first data.sort(); - rayon(&data) + rayon(&data); +} + +pub fn rayon_sorted_reverse(data: &[Task]) { + let mut data = data.to_vec(); + // Longest tasks first + data.sort_by(|a, b| a.cmp(b).reverse()); + rayon(&data); }