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); }