Skip to content

Commit a4cca36

Browse files
committed
bench: Check fold's performance
1 parent da8cc5f commit a4cca36

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

benches/bench.rs

+39
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ fn simple() -> String {
4545
rendered
4646
}
4747

48+
#[divan::bench(args=[0, 1, 10, 100, 1_000, 10_000, 100_000])]
49+
fn fold(bencher: divan::Bencher<'_, '_>, context: usize) {
50+
bencher
51+
.with_inputs(|| {
52+
let line = "012345678901234567890123456789";
53+
let mut input = String::new();
54+
for _ in 1..=context {
55+
input.push_str(line);
56+
input.push('\n');
57+
}
58+
let span_start = input.len() + line.len();
59+
let span = span_start..span_start;
60+
61+
input.push_str(line);
62+
input.push('\n');
63+
for _ in 1..=context {
64+
input.push_str(line);
65+
input.push('\n');
66+
}
67+
(input, span)
68+
})
69+
.bench_values(|(input, span)| {
70+
let message = Level::Error.title("mismatched types").id("E0308").snippet(
71+
Snippet::source(&input)
72+
.fold(true)
73+
.origin("src/format.rs")
74+
.annotation(
75+
Level::Warning
76+
.span(span)
77+
.label("expected `Option<String>` because of return type"),
78+
),
79+
);
80+
81+
let renderer = Renderer::plain();
82+
let rendered = renderer.render(message).to_string();
83+
rendered
84+
});
85+
}
86+
4887
fn main() {
4988
divan::main();
5089
}

0 commit comments

Comments
 (0)