Compare commits

...

3 commits

Author SHA1 Message Date
Rodolphe Bréard
d8f34487dc Add the rayon and rayon_sorted algorithms 2024-10-30 21:21:40 +01:00
Rodolphe Bréard
a6afc0b406 Rename the benchmark 2024-10-30 21:08:19 +01:00
Rodolphe Bréard
06573ed2a0 Fix typos 2024-10-30 20:45:10 +01:00
6 changed files with 44 additions and 16 deletions

View file

@ -9,11 +9,12 @@ publish = false
[dependencies]
pbkdf2 = "0.12.2"
rayon = { version = "1.10.0", default-features = false }
sha2 = "0.10.8"
[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
[[bench]]
name = "small"
name = "job_scheduling"
harness = false

View file

@ -23,9 +23,8 @@ the [optimal job scheduling problem][ojs problem] and can often be seen as a
### Example
If we have 4 tasks tasks to execute. Three of then takes 1 second each to
execute and the last one takes 3 seconds. We have 2 processing units of equal
power.
We have 4 tasks tasks to execute. Three of them takes 1 second each to execute
and the last one takes 3 seconds. We have 2 processing units of equal power.
If each processing unit starts by executing one of the 1s tasks, they will both
finis this job after one second. Then, one of those processing unit will

26
benches/job_scheduling.rs Normal file
View file

@ -0,0 +1,26 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rust_job_scheduling::algorithm::*;
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),
("rayon", &rayon),
("rayon sorted", &rayon_sorted),
];
fn job_scheduling_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("job_scheduling");
for (data_name, data) in TEST_DATA {
for (func_name, func) in TEST_FUNCS {
group.bench_with_input(BenchmarkId::new(*func_name, data_name), data, |b, i| {
b.iter(|| func(i))
});
}
}
group.finish();
}
criterion_group!(benches, job_scheduling_benchmark);
criterion_main!(benches);

View file

@ -1,12 +0,0 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rust_job_scheduling::algorithm::*;
use rust_job_scheduling::data::SMALL;
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("single thread", |b| {
b.iter(|| single_thread(black_box(SMALL)))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

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