diff --git a/Cargo.toml b/Cargo.toml index dafe03c..2c5c58f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/benches/job_scheduling.rs b/benches/job_scheduling.rs index f7f68b8..3ac854d 100644 --- a/benches/job_scheduling.rs +++ b/benches/job_scheduling.rs @@ -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"); diff --git a/src/algorithm.rs b/src/algorithm.rs index 0ebf2b7..7075acb 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -1,3 +1,5 @@ +mod rayon; mod single_thread; +pub use rayon::{rayon, rayon_sorted}; pub use single_thread::single_thread; diff --git a/src/algorithm/rayon.rs b/src/algorithm/rayon.rs new file mode 100644 index 0000000..0fad83b --- /dev/null +++ b/src/algorithm/rayon.rs @@ -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) +}