Skip to content

Commit

Permalink
feat(benchmark): add transformer benchmark (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Sep 16, 2023
1 parent 70189f9 commit 540fa03
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
steps:
- name: Checkout Branch
uses: actions/checkout@v4
with:
submodules: true # Pull submodules for additional files

- name: Install Rust Toolchain
uses: ./.github/actions/rustup
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ oxc_type_synthesis = { path = "crates/oxc_type_synthesis" }
oxc_resolver = { path = "crates/oxc_resolver" }
oxc_query = { path = "crates/oxc_query" }
oxc_linter_plugin = { path = "crates/oxc_linter_plugin" }
oxc_transformer = { path = "crates/oxc_transformer" }

oxc_tasks_common = { path = "tasks/common" }
oxc_vscode = { path = "editor/vscode/server" }
Expand Down
5 changes: 5 additions & 0 deletions tasks/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ bench = false
name = "parser"
harness = false

[[bench]]
name = "transformer"
harness = false

[[bench]]
name = "semantic"
harness = false
Expand All @@ -42,6 +46,7 @@ oxc_tasks_common = { workspace = true }
oxc_semantic = { workspace = true }
oxc_resolver = { workspace = true }
oxc_linter = { workspace = true }
oxc_transformer = { workspace = true }
rayon = { workspace = true }
criterion = { workspace = true }
codspeed-criterion-compat = { workspace = true, optional = true }
Expand Down
44 changes: 44 additions & 0 deletions tasks/benchmark/benches/transformer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(target_os = "windows")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use std::{fs, hint::black_box};

use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_tasks_common::project_root;
use oxc_transformer::{TransformOptions, Transformer};

fn bench_transformer(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("transformer");

let dir = project_root().join("tasks/coverage/typescript/src/compiler");
let files = ["binder.ts", "scanner.ts", "checker.ts", "parser.ts"];

for file in files {
let path = dir.join(file);
let source_text = fs::read_to_string(&path).unwrap();
let source_type = SourceType::from_path(file).unwrap();
let id = BenchmarkId::from_parameter(file);
group.bench_with_input(id, &source_text, |b, source_text| {
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
let transform_options = TransformOptions::default();
b.iter(|| {
Transformer::new(&allocator, &transform_options).build(black_box(program));
});
});
}

group.finish();
}

criterion_group!(transformer, bench_transformer);
criterion_main!(transformer);

0 comments on commit 540fa03

Please sign in to comment.