2021-09-29 15:10:38 +03:00
|
|
|
extern crate swc_node_base;
|
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};
|
2019-11-23 17:03:19 +03:00
|
|
|
use swc_common::FileName;
|
2020-07-31 12:49:07 +03:00
|
|
|
use swc_ecma_parser::{lexer::Lexer, StringInput, Syntax};
|
2019-11-23 17:03:19 +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, _| {
|
2019-11-23 17:03:19 +03:00
|
|
|
let fm = cm.new_source_file(FileName::Anon, src.into());
|
|
|
|
|
|
|
|
b.iter(|| {
|
2020-07-31 12:49:07 +03:00
|
|
|
let lexer = Lexer::new(syntax, Default::default(), StringInput::from(&*fm), None);
|
2019-11-23 17:03:19 +03:00
|
|
|
for t in lexer {
|
|
|
|
black_box(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
}
|
2022-04-03 18:56:29 +03:00
|
|
|
|
|
|
|
fn bench_files(c: &mut Criterion) {
|
|
|
|
c.bench_function("colors", |b| {
|
|
|
|
// Copied from ratel-rust
|
|
|
|
bench_module(b, Default::default(), include_str!("../colors.js"))
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("angular", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/angular-1.2.5.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("backbone", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/backbone-1.1.0.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2022-04-11 21:45:58 +03:00
|
|
|
c.bench_function("jquery", |b| {
|
2022-04-03 18:56:29 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery-1.9.1.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("jquery mobile", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery.mobile-1.4.2.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
c.bench_function("mootools", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/mootools-1.4.5.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("underscore", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/underscore-1.5.2.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("three", |b| {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/three-0.138.3.js"),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
c.bench_function("yui", |b| {
|
|
|
|
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_files);
|
|
|
|
criterion_main!(benches);
|