2019-12-13 09:21:25 +03:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
static GLOBAL: System = System;
|
|
|
|
|
|
|
|
use std::alloc::System;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_common::{chain, FileName};
|
2020-07-25 14:26:04 +03:00
|
|
|
use swc_ecma_parser::{Parser, SourceFileInput, Syntax};
|
2019-12-13 09:21:25 +03:00
|
|
|
use swc_ecma_transforms::helpers;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_visit::FoldWith;
|
2019-12-13 09:21:25 +03:00
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
static SOURCE: &str = include_str!("../../parser/benches/files/angular-1.2.5.js");
|
|
|
|
|
|
|
|
/// Benchmark a folder
|
|
|
|
macro_rules! tr {
|
|
|
|
($b:expr, $tr:expr) => {
|
|
|
|
$b.bytes = SOURCE.len() as _;
|
|
|
|
|
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-07-25 14:26:04 +03:00
|
|
|
let mut parser = Parser::new(Syntax::default(), SourceFileInput::from(&*fm), None);
|
|
|
|
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();
|
|
|
|
test::black_box(module.fold_with(&mut tr))
|
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn resolver(b: &mut Bencher) {
|
|
|
|
tr!(b, || swc_ecma_transforms::resolver());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn fixer(b: &mut Bencher) {
|
|
|
|
tr!(b, || swc_ecma_transforms::fixer());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn hygiene(b: &mut Bencher) {
|
|
|
|
tr!(b, || swc_ecma_transforms::hygiene());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn resolver_with_hygiene(b: &mut Bencher) {
|
|
|
|
tr!(b, || chain!(
|
|
|
|
swc_ecma_transforms::resolver(),
|
|
|
|
swc_ecma_transforms::hygiene()
|
|
|
|
));
|
|
|
|
}
|