feat(benchmark): add transformer benchmark (#919)

This commit is contained in:
Boshen 2023-09-16 17:09:27 +08:00 committed by GitHub
parent 70189f9758
commit 540fa03ec0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 0 deletions

View file

@ -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

1
Cargo.lock generated
View file

@ -1458,6 +1458,7 @@ dependencies = [
"oxc_semantic",
"oxc_span",
"oxc_tasks_common",
"oxc_transformer",
"rayon",
]

View file

@ -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" }

View file

@ -17,6 +17,10 @@ bench = false
name = "parser"
harness = false
[[bench]]
name = "transformer"
harness = false
[[bench]]
name = "semantic"
harness = false
@ -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 }

View file

@ -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);