|
1 |
| -use criterion::{criterion_group, criterion_main, Criterion}; |
| 1 | +use divan::{black_box, AllocProfiler, Bencher}; |
2 | 2 | use harper_core::{Dictionary, Document, LintSet, Linter};
|
3 | 3 |
|
4 |
| -fn parse_demo(c: &mut Criterion) { |
5 |
| - let demo = include_str!("../../demo.md"); |
| 4 | +#[global_allocator] |
| 5 | +static ALLOC: AllocProfiler = AllocProfiler::system(); |
6 | 6 |
|
7 |
| - c.bench_function("parse_demo", |b| { |
8 |
| - b.iter(|| { |
9 |
| - let _document = Document::new_markdown(demo); |
10 |
| - }) |
| 7 | +static DEMO: &str = include_str!("../../demo.md"); |
| 8 | + |
| 9 | +#[divan::bench] |
| 10 | +fn parse_demo(bencher: Bencher) { |
| 11 | + bencher.bench_local(|| { |
| 12 | + let _document = Document::new_markdown(black_box(DEMO)); |
11 | 13 | });
|
| 14 | +} |
12 | 15 |
|
| 16 | +#[divan::bench] |
| 17 | +fn create_lint_set(bencher: Bencher) { |
13 | 18 | let dictionary = Dictionary::new();
|
14 | 19 |
|
15 |
| - c.bench_function("create_lint_set", |b| { |
16 |
| - b.iter(|| { |
17 |
| - let _lint_set = LintSet::new().with_standard(dictionary.clone()); |
18 |
| - }) |
| 20 | + bencher.bench_local(|| { |
| 21 | + let _lint_set = LintSet::new().with_standard(dictionary.clone()); |
19 | 22 | });
|
| 23 | +} |
20 | 24 |
|
| 25 | +#[divan::bench] |
| 26 | +fn lint_demo(bencher: Bencher) { |
| 27 | + let dictionary = Dictionary::new(); |
21 | 28 | let mut lint_set = LintSet::new().with_standard(dictionary);
|
22 |
| - let document = Document::new_markdown(demo); |
| 29 | + let document = Document::new_markdown(black_box(DEMO)); |
23 | 30 |
|
24 |
| - c.bench_function("lint_demo", |b| { |
25 |
| - b.iter(|| { |
26 |
| - lint_set.lint(&document); |
27 |
| - }) |
| 31 | + bencher.bench_local(|| { |
| 32 | + lint_set.lint(&document); |
28 | 33 | });
|
29 | 34 | }
|
30 | 35 |
|
31 |
| -criterion_group!(benches, parse_demo); |
32 |
| -criterion_main!(benches); |
| 36 | +fn main() { |
| 37 | + divan::main(); |
| 38 | +} |
0 commit comments