2021-09-29 15:10:38 +03:00
|
|
|
extern crate swc_node_base;
|
2019-12-13 09:21:25 +03:00
|
|
|
|
2022-04-03 18:56:29 +03:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
|
2021-08-13 13:03:04 +03:00
|
|
|
use swc_common::{comments::SingleThreadedComments, FileName};
|
2020-07-31 12:49:07 +03:00
|
|
|
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax};
|
2018-12-21 10:54:36 +03:00
|
|
|
|
2019-11-22 15:13:14 +03:00
|
|
|
fn bench_module(b: &mut Bencher, syntax: Syntax, src: &'static str) {
|
2020-07-25 14:26:04 +03:00
|
|
|
let _ = ::testing::run_test(false, |cm, _| {
|
2021-05-11 07:53:36 +03:00
|
|
|
let comments = SingleThreadedComments::default();
|
2019-02-10 14:49:29 +03:00
|
|
|
let fm = cm.new_source_file(FileName::Anon, src.into());
|
2018-11-17 04:02:40 +03:00
|
|
|
|
2018-12-01 16:24:26 +03:00
|
|
|
b.iter(|| {
|
2022-04-03 18:56:29 +03:00
|
|
|
let _ = black_box({
|
2021-05-11 07:53:36 +03:00
|
|
|
let lexer = Lexer::new(
|
|
|
|
syntax,
|
|
|
|
Default::default(),
|
|
|
|
StringInput::from(&*fm),
|
|
|
|
Some(&comments),
|
|
|
|
);
|
2020-07-25 14:26:04 +03:00
|
|
|
let mut parser = Parser::new_from(lexer);
|
2019-02-08 07:00:58 +03:00
|
|
|
parser.parse_module()
|
|
|
|
});
|
2018-12-01 16:24:26 +03:00
|
|
|
});
|
2018-11-17 04:02:40 +03:00
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
}
|
2022-04-03 18:56:29 +03:00
|
|
|
|
|
|
|
fn bench_files(c: &mut Criterion) {
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/colors", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
// Copied from ratel-rust
|
|
|
|
bench_module(b, Default::default(), include_str!("../colors.js"))
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/angular", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/angular-1.2.5.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/backbone", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/backbone-1.1.0.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/jquery", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery-1.9.1.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/jquery mobile", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery.mobile-1.4.2.js"),
|
|
|
|
)
|
|
|
|
});
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/mootools", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/mootools-1.4.5.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/underscore", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/underscore-1.5.2.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/three", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/three-0.138.3.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:36:15 +03:00
|
|
|
c.bench_function("es/parser/yui", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_files);
|
|
|
|
criterion_main!(benches);
|