Skip to content

Commit

Permalink
chore(benchmark): add codegen benchmark (#4207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Jul 11, 2024
1 parent 2602ce2 commit 91dc0f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- isolated_declarations
- semantic
- minifier
- codegen_sourcemap
- codegen
- sourcemap

steps:
Expand Down
4 changes: 2 additions & 2 deletions tasks/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ name = "linter"
harness = false

[[bench]]
name = "codegen_sourcemap"
name = "codegen"
harness = false

[[bench]]
Expand Down Expand Up @@ -112,7 +112,7 @@ parser = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_tasks_
transformer = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_tasks_common", "dep:oxc_transformer"]
semantic = ["dep:oxc_allocator", "dep:oxc_parser", "dep:oxc_semantic", "dep:oxc_span", "dep:oxc_tasks_common"]
minifier = ["dep:oxc_allocator", "dep:oxc_minifier", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_tasks_common"]
codegen_sourcemap = ["dep:oxc_allocator", "dep:oxc_codegen", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_tasks_common"]
codegen = ["dep:oxc_allocator", "dep:oxc_codegen", "dep:oxc_parser", "dep:oxc_span", "dep:oxc_tasks_common"]
sourcemap = [
"dep:oxc_allocator",
"dep:oxc_codegen",
Expand Down
33 changes: 33 additions & 0 deletions tasks/benchmark/benches/codegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_codegen::CodeGenerator;
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_tasks_common::TestFiles;

fn bench_codegen(criterion: &mut Criterion) {
for file in TestFiles::complicated_one(0).files() {
let id = BenchmarkId::from_parameter(&file.file_name);
let source_type = SourceType::from_path(&file.file_name).unwrap();
let allocator = Allocator::default();
let source_text = &file.source_text;
let ret = Parser::new(&allocator, source_text, source_type).parse();

let mut group = criterion.benchmark_group("codegen");
group.bench_with_input(id.clone(), &ret.program, |b, program| {
b.iter_with_large_drop(|| CodeGenerator::new().build(program).source_map);
});
group.finish();

let mut group = criterion.benchmark_group("codegen_sourcemap");
group.bench_with_input(id, &ret.program, |b, program| {
b.iter_with_large_drop(|| {
CodeGenerator::new().enable_source_map(&file.file_name, source_text).build(program)
});
});
group.finish();
}
}

criterion_group!(codegen, bench_codegen);
criterion_main!(codegen);
30 changes: 0 additions & 30 deletions tasks/benchmark/benches/codegen_sourcemap.rs

This file was deleted.

0 comments on commit 91dc0f7

Please sign in to comment.