forked from LiveSplit/livesplit-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
layout_state.rs
70 lines (53 loc) · 1.74 KB
/
layout_state.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use criterion::{criterion_group, criterion_main, Criterion};
use livesplit_core::{run::parser::livesplit, Layout, Run, Segment, Timer};
use std::fs;
criterion_main!(benches);
criterion_group!(
benches,
no_reuse_real,
reuse_real,
no_reuse_artificial,
reuse_artificial
);
fn artificial() -> (Timer, Layout) {
let mut run = Run::new();
run.set_game_name("Game");
run.set_category_name("Category");
run.push_segment(Segment::new("Foo"));
let mut timer = Timer::new(run).unwrap();
timer.start();
(timer, Layout::default_layout())
}
fn real() -> (Timer, Layout) {
let buf = fs::read_to_string("tests/run_files/Celeste - Any% (1.2.1.5).lss").unwrap();
let run = livesplit::parse(&buf).unwrap();
let mut timer = Timer::new(run).unwrap();
timer.start();
(timer, Layout::default_layout())
}
fn no_reuse_real(c: &mut Criterion) {
let (timer, mut layout) = real();
c.bench_function("No Reuse (Real)", move |b| {
b.iter(|| layout.state(&timer.snapshot()))
});
}
fn reuse_real(c: &mut Criterion) {
let (timer, mut layout) = real();
let mut state = layout.state(&timer.snapshot());
c.bench_function("Reuse (Real)", move |b| {
b.iter(|| layout.update_state(&mut state, &timer.snapshot()))
});
}
fn no_reuse_artificial(c: &mut Criterion) {
let (timer, mut layout) = artificial();
c.bench_function("No Reuse (Artificial)", move |b| {
b.iter(|| layout.state(&timer.snapshot()))
});
}
fn reuse_artificial(c: &mut Criterion) {
let (timer, mut layout) = artificial();
let mut state = layout.state(&timer.snapshot());
c.bench_function("Reuse (Artificial)", move |b| {
b.iter(|| layout.update_state(&mut state, &timer.snapshot()))
});
}