Compare commits
3 commits
fa3dbd719d
...
d8f34487dc
Author | SHA1 | Date | |
---|---|---|---|
|
d8f34487dc | ||
|
a6afc0b406 | ||
|
06573ed2a0 |
6 changed files with 44 additions and 16 deletions
|
@ -9,11 +9,12 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pbkdf2 = "0.12.2"
|
pbkdf2 = "0.12.2"
|
||||||
|
rayon = { version = "1.10.0", default-features = false }
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.5.1", features = ["html_reports"] }
|
criterion = { version = "0.5.1", features = ["html_reports"] }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "small"
|
name = "job_scheduling"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
|
@ -23,9 +23,8 @@ the [optimal job scheduling problem][ojs problem] and can often be seen as a
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
If we have 4 tasks tasks to execute. Three of then takes 1 second each to
|
We have 4 tasks tasks to execute. Three of them takes 1 second each to execute
|
||||||
execute and the last one takes 3 seconds. We have 2 processing units of equal
|
and the last one takes 3 seconds. We have 2 processing units of equal power.
|
||||||
power.
|
|
||||||
|
|
||||||
If each processing unit starts by executing one of the 1s tasks, they will both
|
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
|
finis this job after one second. Then, one of those processing unit will
|
||||||
|
|
26
benches/job_scheduling.rs
Normal file
26
benches/job_scheduling.rs
Normal 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);
|
|
@ -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);
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
mod rayon;
|
||||||
mod single_thread;
|
mod single_thread;
|
||||||
|
|
||||||
|
pub use rayon::{rayon, rayon_sorted};
|
||||||
pub use single_thread::single_thread;
|
pub use single_thread::single_thread;
|
||||||
|
|
12
src/algorithm/rayon.rs
Normal file
12
src/algorithm/rayon.rs
Normal 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)
|
||||||
|
}
|
Loading…
Reference in a new issue