oxc/tasks/benchmark/benches/linter.rs
Boshen 601153fe8f
refactor(benchmark): use more complicated files (#1811)
closes #1806

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2023-12-25 17:27:02 +08:00

54 lines
2.1 KiB
Rust

#[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::{path::PathBuf, rc::Rc};
use oxc_allocator::Allocator;
use oxc_benchmark::{criterion_group, criterion_main, BenchmarkId, Criterion};
use oxc_linter::{AllowWarnDeny, LintContext, LintOptions, LintSettings, Linter};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_tasks_common::TestFiles;
fn bench_linter(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("linter");
for file in TestFiles::complicated().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 ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(source_text, source_type)
.with_trivias(ret.trivias)
.build_module_record(PathBuf::new(), program)
.build(program);
let lint_options = LintOptions::default()
.with_filter(vec![(AllowWarnDeny::Deny, "all".into())])
.with_jest_plugin(true)
.with_jsx_a11y_plugin(true);
let linter = Linter::from_options(lint_options).unwrap();
let semantic = Rc::new(semantic_ret.semantic);
b.iter(|| {
linter.run(LintContext::new(
PathBuf::from("").into_boxed_path(),
&semantic,
LintSettings::default(),
))
});
},
);
}
group.finish();
}
criterion_group!(linter, bench_linter);
criterion_main!(linter);