Add the rayon_sorted_reverse algorithm

This commit is contained in:
Rodolphe Bréard 2024-10-30 22:23:55 +01:00
parent f1e158fb4d
commit 501179f5fd
2 changed files with 10 additions and 1 deletions

View file

@ -8,6 +8,7 @@ const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[
("single thread", &single_thread), ("single thread", &single_thread),
("rayon", &rayon), ("rayon", &rayon),
("rayon sorted", &rayon_sorted), ("rayon sorted", &rayon_sorted),
("rayon sorted reverse", &rayon_sorted_reverse),
]; ];
fn job_scheduling_benchmark(c: &mut Criterion) { fn job_scheduling_benchmark(c: &mut Criterion) {

View file

@ -7,6 +7,14 @@ pub fn rayon(data: &[Task]) {
pub fn rayon_sorted(data: &[Task]) { pub fn rayon_sorted(data: &[Task]) {
let mut data = data.to_vec(); let mut data = data.to_vec();
// Shortest tasks first
data.sort(); 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);
} }