Skip to content

Commit 2a22769

Browse files
refactor parsing benchmarks to measure actual parsing
1 parent de2dbec commit 2a22769

1 file changed

Lines changed: 24 additions & 29 deletions

File tree

crates/djls-bench/benches/parser.rs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,39 @@ fn main() {
99

1010
#[divan::bench(args = template_fixtures())]
1111
fn parse_template(bencher: Bencher, fixture: &TemplateFixture) {
12-
bencher
13-
.with_inputs(|| {
14-
let mut db = Db::new();
15-
let file = db.file_with_contents(fixture.path.clone(), &fixture.source);
16-
(db, file)
17-
})
18-
.bench_local_values(|(db, file)| {
19-
if let Some(nodelist) = djls_templates::parse_template(&db, file) {
20-
divan::black_box(nodelist.nodelist(&db).len());
21-
}
22-
(db, file)
23-
});
12+
let mut db = Db::new();
13+
14+
let mut revision: u64 = 1;
15+
bencher.bench_local(move || {
16+
let path = format!("{}.bench{}", fixture.path.clone(), revision);
17+
let file = db.file_with_contents(path.into(), &fixture.source);
18+
19+
if let Some(nodelist) = djls_templates::parse_template(&db, file) {
20+
divan::black_box(nodelist.nodelist(&db).len());
21+
}
22+
23+
revision = revision.wrapping_add(1);
24+
});
2425
}
2526

2627
#[divan::bench]
2728
fn parse_all_templates(bencher: Bencher) {
2829
let fixtures = template_fixtures();
30+
let mut db = Db::new();
2931

30-
bencher
31-
.with_inputs(|| {
32-
let mut db = Db::new();
33-
let mut files = Vec::with_capacity(fixtures.len());
32+
let mut revision: u64 = 1;
33+
bencher.bench_local(move || {
34+
for fixture in fixtures {
35+
let path = format!("{}.bench{}", fixture.path, revision);
36+
let file = db.file_with_contents(path.into(), &fixture.source);
3437

35-
for fixture in fixtures {
36-
let file = db.file_with_contents(fixture.path.clone(), &fixture.source);
37-
files.push(file);
38+
if let Some(nodelist) = djls_templates::parse_template(&db, file) {
39+
divan::black_box(nodelist.nodelist(&db).len());
3840
}
41+
}
3942

40-
(db, files)
41-
})
42-
.bench_local_values(|(db, files)| {
43-
for file in &files {
44-
if let Some(nodelist) = djls_templates::parse_template(&db, *file) {
45-
divan::black_box(nodelist.nodelist(&db).len());
46-
}
47-
}
48-
(db, files)
49-
});
43+
revision = revision.wrapping_add(1);
44+
});
5045
}
5146

5247
#[divan::bench(args = template_fixtures())]

0 commit comments

Comments
 (0)