Skip to content

Commit

Permalink
chore(coverage): add a prepass benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 20, 2024
1 parent a5e0f22 commit ebb6eb8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
3 changes: 1 addition & 2 deletions crates/oxc_minifier/examples/minifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use pico_args::Arguments;

// Instruction:
// create a `test.js`,
// run `cargo run -p oxc_minifier --example minifier`
// or `just watch "run -p oxc_minifier --example minifier"`
// run `cargo run -p oxc_minifier --example minifier` or `just example minifier`

fn main() -> std::io::Result<()> {
let mut args = Arguments::from_env();
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_minifier/src/compressor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use oxc_syntax::{
precedence::GetPrecedence,
};

pub use self::options::CompressOptions;
use self::prepass::Prepass;
pub use self::{options::CompressOptions, prepass::Prepass};

pub struct Compressor<'a> {
ast: AstBuilder<'a>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_allocator::Allocator;
use oxc_ast::ast::Program;

pub use crate::{
compressor::{CompressOptions, Compressor},
compressor::{CompressOptions, Compressor, Prepass},
mangler::ManglerBuilder,
};

Expand Down
24 changes: 22 additions & 2 deletions tasks/benchmark/benches/minifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_minifier::{Minifier, MinifierOptions};
use oxc_minifier::{Minifier, MinifierOptions, Prepass};
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_tasks_common::TestFiles;
Expand All @@ -27,5 +27,25 @@ fn bench_minifier(criterion: &mut Criterion) {
group.finish();
}

criterion_group!(minifier, bench_minifier);
fn bench_passes(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("prepass");

for file in TestFiles::minimal().files() {
let source_type = SourceType::from_path(&file.file_name).unwrap();
group.bench_with_input(
BenchmarkId::from_parameter(&file.file_name),
&file.source_text,
|b, source_text| {
let allocator = Allocator::default();
let program = Parser::new(&allocator, source_text, source_type).parse().program;
let program = allocator.alloc(program);
b.iter(|| Prepass::new(&allocator).build(program));
},
);
}

group.finish();
}

criterion_group!(minifier, bench_minifier, bench_passes);
criterion_main!(minifier);

0 comments on commit ebb6eb8

Please sign in to comment.