rust_job_scheduling/benches/job_scheduling.rs

31 lines
962 B
Rust
Raw Permalink Normal View History

2024-10-30 21:08:19 +01:00
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rust_job_scheduling::algorithm::*;
2024-10-30 21:54:25 +01:00
use rust_job_scheduling::data::*;
2024-10-30 21:08:19 +01:00
use rust_job_scheduling::Task;
2024-10-30 21:55:11 +01:00
const TEST_DATA: &[(&str, &[Task])] = &[("10 tasks", T_10), ("500 tasks", T_500)];
const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[
("single thread", &single_thread),
2024-10-30 23:39:03 +01:00
("multi threads", &multi_threads),
2024-10-30 23:22:44 +01:00
("lpt", &lpt),
("rayon", &rayon),
("rayon sorted", &rayon_sorted),
2024-10-30 22:23:55 +01:00
("rayon sorted reverse", &rayon_sorted_reverse),
("rayon sorted reverse 2", &rayon_sorted_reverse_2),
];
2024-10-30 21:08:19 +01:00
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);