Parallelize DFS, use an AtomicBool for short-circuiting

time:   [73.407 µs 76.145 µs 79.345 µs]
change: [−40.126% −24.679% −3.8062%] (p = 0.04 < 0.05)
This commit is contained in:
2026-02-01 22:53:04 +02:00
parent c9e1d3ab67
commit 98cb9f7f3e
6 changed files with 375 additions and 5 deletions

View File

@@ -0,0 +1,53 @@
use std::hint::black_box;
use criterion::{criterion_group, criterion_main, Criterion};
use rota_lib::{
config::{ToxicPair, UserConfig},
resident::Resident,
schedule::{MonthlySchedule, ShiftType},
scheduler::Scheduler,
slot::Day,
workload::WorkloadTracker,
};
fn criterion_benchmark(c: &mut Criterion) {
let config = maximal_config();
let scheduler = Scheduler::new_with_config(config);
c.bench_function("scheduler run", |b| {
b.iter(|| {
let mut schedule = MonthlySchedule::new();
let mut tracker = WorkloadTracker::default();
let result = scheduler.run(&mut schedule, &mut tracker);
black_box(result)
})
});
}
fn maximal_config() -> UserConfig {
UserConfig::default()
.with_holidays(vec![2, 3, 10, 11, 12, 25])
.with_residents(vec![
Resident::new(1, "R1").with_max_shifts(3),
Resident::new(2, "R2").with_max_shifts(4),
Resident::new(3, "R3").with_reduced_load(),
Resident::new(4, "R4").with_allowed_types(vec![ShiftType::Closed]),
Resident::new(5, "R5")
.with_allowed_types(vec![ShiftType::OpenFirst, ShiftType::OpenSecond]),
Resident::new(6, "R6").with_negative_shifts(vec![Day(5), Day(15), Day(25)]),
Resident::new(7, "R7")
.with_allowed_types(vec![ShiftType::OpenFirst, ShiftType::OpenSecond]),
Resident::new(8, "R8"),
Resident::new(9, "R9"),
Resident::new(10, "R10").with_reduced_load(),
])
.with_toxic_pairs(vec![
ToxicPair::new(1, 2),
ToxicPair::new(3, 4),
ToxicPair::new(3, 5),
ToxicPair::new(7, 8),
])
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);