Skip to content

Commit

Permalink
add benchmark to cover parse_module
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed May 28, 2022
1 parent b041f5f commit 00f9f2e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions native/libcst/benches/parser_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn parser_benchmarks<T: Measurement>(c: &mut Criterion<T>) {

pub fn codegen_benchmarks<T: Measurement>(c: &mut Criterion<T>) {
let input = load_all_fixtures();
let m = parse_module(&input, None).expect("parse failed");
let m = parse_module(input.as_str(), None).expect("parse failed");
let mut group = c.benchmark_group("codegen");
group.bench_function("all", |b| {
b.iter(|| {
Expand All @@ -107,9 +107,19 @@ pub fn tokenize_benchmarks<T: Measurement>(c: &mut Criterion<T>) {
group.finish();
}

pub fn parse_into_cst_benchmarks<T: Measurement>(c: &mut Criterion<T>) {
let fixture = load_all_fixtures();
let mut group = c.benchmark_group("parse_into_cst");
group.measurement_time(Duration::from_secs(15));
group.bench_function("all", |b| {
b.iter(|| black_box(parse_module(&fixture, None)))
});
group.finish();
}

criterion_group!(
name=benches;
config = Criterion::default().with_measurement(CyclesPerByte);
targets=parser_benchmarks, codegen_benchmarks, inflate_benchmarks, tokenize_benchmarks
targets=parser_benchmarks, codegen_benchmarks, inflate_benchmarks, tokenize_benchmarks, parse_into_cst_benchmarks
);
criterion_main!(benches);

0 comments on commit 00f9f2e

Please sign in to comment.