mirror of
https://github.com/danbulant/oxc
synced 2026-05-22 21:58:36 +00:00
This PR introduces two type alias to avoid the confusing const generic `pub struct Codegen<'a, const MINIFY: bool>` * CodeGenerator - Code generator without whitespace removal. * WhitespaceRemover - Code generator with whitespace removal. Usage is changed to a builder pattern: ```rust CodeGenerator::new() .enable_comment(...) .enable_sourcemap(...) .build(&program); ```
39 lines
1.6 KiB
Rust
39 lines
1.6 KiB
Rust
use oxc_allocator::Allocator;
|
|
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
use oxc_codegen::{CodeGenerator, CodegenReturn};
|
|
use oxc_parser::Parser;
|
|
use oxc_sourcemap::ConcatSourceMapBuilder;
|
|
use oxc_span::SourceType;
|
|
use oxc_tasks_common::TestFiles;
|
|
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
fn bench_sourcemap(criterion: &mut Criterion) {
|
|
let mut group = criterion.benchmark_group("sourcemap");
|
|
|
|
for file in TestFiles::complicated_one(1).files() {
|
|
let id = BenchmarkId::from_parameter(&file.file_name);
|
|
let source_type = SourceType::from_path(&file.file_name).unwrap();
|
|
group.bench_with_input(id, &file.source_text, |b, source_text| {
|
|
let allocator = Allocator::default();
|
|
let ret = Parser::new(&allocator, source_text, source_type).parse();
|
|
b.iter(|| {
|
|
let CodegenReturn { source_map, source_text } = CodeGenerator::new()
|
|
.enable_source_map(file.file_name.as_str(), source_text)
|
|
.build(&ret.program);
|
|
let line = source_text.matches('\n').count() as u32;
|
|
if let Some(sourcemap) = source_map {
|
|
let mut concat_sourcemap_builder = ConcatSourceMapBuilder::default();
|
|
for i in 0..1 {
|
|
concat_sourcemap_builder.add_sourcemap(&sourcemap, line * i);
|
|
}
|
|
concat_sourcemap_builder.into_sourcemap().to_json_string().unwrap();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(sourcemap, bench_sourcemap);
|
|
criterion_main!(sourcemap);
|