forked from LiveSplit/livesplit-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
balanced_pb.rs
56 lines (42 loc) · 1.61 KB
/
balanced_pb.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use criterion::{criterion_group, criterion_main, Criterion};
use livesplit_core::{
comparison::balanced_pb::BalancedPB, run::parser::livesplit, Run, Segment, TimeSpan, Timer,
};
use std::fs;
criterion_main!(benches);
criterion_group!(benches, fake_splits, actual_splits);
fn run_with_splits(timer: &mut Timer, splits: &[f64]) {
timer.start();
timer.initialize_game_time();
timer.pause_game_time();
for &split in splits {
timer.set_game_time(TimeSpan::from_seconds(split));
timer.split();
}
timer.reset(true);
}
fn fake_splits(c: &mut Criterion) {
let mut run = Run::new();
run.push_segment(Segment::new("First"));
run.push_segment(Segment::new("Second"));
run.push_segment(Segment::new("Third"));
run.comparison_generators_mut().clear();
run.comparison_generators_mut().push(Box::new(BalancedPB));
let mut timer = Timer::new(run).unwrap();
run_with_splits(&mut timer, &[1.0, 2.0, 3.0]);
run_with_splits(&mut timer, &[0.5, 2.5, 3.0]);
run_with_splits(&mut timer, &[0.2, 2.8, 3.0]);
let mut run = timer.into_run(false);
c.bench_function("Balanced PB for synthetic splits", move |b| {
b.iter(|| run.regenerate_comparisons())
});
}
fn actual_splits(c: &mut Criterion) {
let buf = fs::read_to_string("tests/run_files/livesplit1.6.lss").unwrap();
let mut run = livesplit::parse(&buf).unwrap();
run.comparison_generators_mut().clear();
run.comparison_generators_mut().push(Box::new(BalancedPB));
c.bench_function("Balanced PB for actual splits", move |b| {
b.iter(|| run.regenerate_comparisons())
});
}