2021-11-26 09:04:41 +03:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
use std::path::Path;
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-11-26 09:04:41 +03:00
|
|
|
use swc_ecma_parser::{EsConfig, Parser, StringInput, Syntax};
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
extern crate swc_node_base;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
/// this benchmark requires real input, which cannot be committed into git
|
|
|
|
/// repository
|
|
|
|
#[bench]
|
|
|
|
#[cfg(not(all))]
|
|
|
|
fn total(b: &mut Bencher) {
|
|
|
|
let input = Path::new("tests/fixture/real/input.js");
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
testing::run_test(false, |cm, handler| {
|
2022-01-13 17:06:11 +03:00
|
|
|
let fm = cm.load_file(input).unwrap();
|
2021-11-26 09:04:41 +03:00
|
|
|
|
|
|
|
let module = {
|
|
|
|
let mut p = Parser::new(
|
|
|
|
Syntax::Es(EsConfig {
|
|
|
|
jsx: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
StringInput::from(&*fm),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
let res = p
|
|
|
|
.parse_module()
|
2022-01-13 17:06:11 +03:00
|
|
|
.map_err(|e| e.into_diagnostic(handler).emit());
|
2021-11-26 09:04:41 +03:00
|
|
|
|
|
|
|
for e in p.take_errors() {
|
2022-01-13 17:06:11 +03:00
|
|
|
e.into_diagnostic(handler).emit()
|
2021-11-26 09:04:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
res?
|
|
|
|
};
|
|
|
|
|
2022-01-13 17:06:11 +03:00
|
|
|
let s = swc_webpack_ast::webpack_ast(cm, fm, module).unwrap();
|
2021-11-26 09:04:41 +03:00
|
|
|
println!("{} bytes", s.len());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
});
|
|
|
|
}
|