mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
Pure refactor. Use `bench_function` instead of `bench_with_input` and just borrow data from outside closure. This shortens the code and (I think) makes it easier to read.
36 lines
1.3 KiB
Rust
36 lines
1.3 KiB
Rust
use oxc_allocator::Allocator;
|
|
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
|
|
use oxc_parser::{Parser, ParserReturn};
|
|
use oxc_span::SourceType;
|
|
use oxc_tasks_common::TestFile;
|
|
|
|
fn bench_isolated_declarations(criterion: &mut Criterion) {
|
|
let mut group = criterion.benchmark_group("isolated-declarations");
|
|
|
|
let file = TestFile::new(
|
|
"https://raw.githubusercontent.com/oxc-project/benchmark-files/main/vue-id.ts",
|
|
);
|
|
|
|
let id = BenchmarkId::from_parameter(&file.file_name);
|
|
let source_text = file.source_text.as_str();
|
|
let source_type = SourceType::from_path(&file.file_name).unwrap();
|
|
|
|
group.bench_function(id, |b| {
|
|
b.iter_with_large_drop(|| {
|
|
let allocator = Allocator::default();
|
|
let ParserReturn { program, .. } =
|
|
Parser::new(&allocator, source_text, source_type).parse();
|
|
IsolatedDeclarations::new(
|
|
&allocator,
|
|
IsolatedDeclarationsOptions { strip_internal: true },
|
|
)
|
|
.build(&program);
|
|
});
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(transformer, bench_isolated_declarations);
|
|
criterion_main!(transformer);
|