oxc/tasks/benchmark/benches/semantic.rs
Boshen 8a788b8f4b feat(parser)!: Build ModuleRecord directly in parser (#7546)
This has the benefit of:

* expose dynamic import / import meta info from parser
* 1 less ast shallow in semantic builder
* no ast walk in oxc's module lexer
* some more benefits coming soon
2024-11-29 14:50:42 +00:00

34 lines
1.5 KiB
Rust

use oxc_allocator::Allocator;
use oxc_benchmark::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_tasks_common::TestFiles;
fn bench_semantic(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("semantic");
for file in TestFiles::complicated().files() {
let source_type = SourceType::from_path(&file.file_name).unwrap();
group.bench_with_input(
BenchmarkId::from_parameter(&file.file_name),
&file.source_text,
|b, source_text| {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
b.iter_with_large_drop(|| {
// We drop `Semantic` inside this closure as drop time is part of cost of using this API.
// We return `error`s to be dropped outside of the measured section, as usually
// code would have no errors. One of our benchmarks `cal.com.tsx` has a lot of errors,
// but that's atypical, so don't want to include it in benchmark time.
let ret = SemanticBuilder::new().with_build_jsdoc(true).build(&ret.program);
let ret = black_box(ret);
ret.errors
});
},
);
}
group.finish();
}
criterion_group!(semantic, bench_semantic);
criterion_main!(semantic);