Add the rayon and rayon_sorted algorithms

This commit is contained in:
Rodolphe Bréard 2024-10-30 21:21:40 +01:00
parent a6afc0b406
commit d8f34487dc
4 changed files with 20 additions and 1 deletions

View file

@ -9,6 +9,7 @@ publish = false
[dependencies]
pbkdf2 = "0.12.2"
rayon = { version = "1.10.0", default-features = false }
sha2 = "0.10.8"
[dev-dependencies]

View file

@ -4,7 +4,11 @@ use rust_job_scheduling::data::SMALL;
use rust_job_scheduling::Task;
const TEST_DATA: &[(&str, &[Task])] = &[("small", SMALL)];
const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[("single thread", &single_thread)];
const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[
("single thread", &single_thread),
("rayon", &rayon),
("rayon sorted", &rayon_sorted),
];
fn job_scheduling_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("job_scheduling");

View file

@ -1,3 +1,5 @@
mod rayon;
mod single_thread;
pub use rayon::{rayon, rayon_sorted};
pub use single_thread::single_thread;

12
src/algorithm/rayon.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::Task;
use rayon::prelude::*;
pub fn rayon(data: &[Task]) {
data.into_par_iter().for_each(|task| task.execute());
}
pub fn rayon_sorted(data: &[Task]) {
let mut data = data.to_vec();
data.sort();
rayon(&data)
}