2019-12-13 09:21:25 +03:00
|
|
|
#[global_allocator]
|
|
|
|
static GLOBAL: System = System;
|
|
|
|
|
|
|
|
use std::alloc::System;
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-04-03 18:56:29 +03:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_common::{chain, FileName};
|
2020-07-31 12:49:07 +03:00
|
|
|
use swc_ecma_parser::{Parser, StringInput, Syntax};
|
2021-01-05 08:29:52 +03:00
|
|
|
use swc_ecma_transforms_base::helpers;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_visit::FoldWith;
|
2019-12-13 09:21:25 +03:00
|
|
|
|
2020-08-26 14:50:18 +03:00
|
|
|
static SOURCE: &str = include_str!("assets/AjaxObservable.ts");
|
2019-12-13 09:21:25 +03:00
|
|
|
|
|
|
|
/// Benchmark a folder
|
|
|
|
macro_rules! tr {
|
|
|
|
($b:expr, $tr:expr) => {
|
2020-07-25 14:26:04 +03:00
|
|
|
let _ = ::testing::run_test(false, |cm, _| {
|
2019-12-13 09:21:25 +03:00
|
|
|
let fm = cm.new_source_file(FileName::Anon, SOURCE.into());
|
|
|
|
|
2020-08-26 14:50:18 +03:00
|
|
|
let mut parser = Parser::new(
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
StringInput::from(&*fm),
|
|
|
|
None,
|
|
|
|
);
|
2020-07-25 14:26:04 +03:00
|
|
|
let module = parser.parse_module().map_err(|_| ()).unwrap();
|
2019-12-13 09:21:25 +03:00
|
|
|
helpers::HELPERS.set(&Default::default(), || {
|
|
|
|
let mut tr = $tr();
|
|
|
|
|
|
|
|
$b.iter(|| {
|
|
|
|
let module = module.clone();
|
2022-04-03 18:56:29 +03:00
|
|
|
black_box(module.fold_with(&mut tr))
|
2019-12-13 09:21:25 +03:00
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolver(b: &mut Bencher) {
|
2022-01-13 17:06:11 +03:00
|
|
|
tr!(b, swc_ecma_transforms_base::resolver::resolver);
|
2019-12-13 09:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fixer(b: &mut Bencher) {
|
2021-01-05 08:29:52 +03:00
|
|
|
tr!(b, || swc_ecma_transforms_base::fixer::fixer(None));
|
2019-12-13 09:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn hygiene(b: &mut Bencher) {
|
2022-01-13 17:06:11 +03:00
|
|
|
tr!(b, swc_ecma_transforms_base::hygiene::hygiene);
|
2019-12-13 09:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn resolver_with_hygiene(b: &mut Bencher) {
|
|
|
|
tr!(b, || chain!(
|
2021-01-05 08:29:52 +03:00
|
|
|
swc_ecma_transforms_base::resolver::resolver(),
|
|
|
|
swc_ecma_transforms_base::hygiene::hygiene()
|
2019-12-13 09:21:25 +03:00
|
|
|
));
|
|
|
|
}
|
2022-04-03 18:56:29 +03:00
|
|
|
|
|
|
|
fn bench_cases(c: &mut Criterion) {
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/transforms/base/resolver", resolver);
|
|
|
|
c.bench_function("es/transforms/base/fixer", fixer);
|
|
|
|
c.bench_function("es/transforms/base/hygiene", hygiene);
|
|
|
|
c.bench_function(
|
|
|
|
"es/transforms/base/resolver_with_hygiene",
|
|
|
|
resolver_with_hygiene,
|
|
|
|
);
|
2022-04-03 18:56:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_cases);
|
|
|
|
criterion_main!(benches);
|