2019-11-23 17:03:19 +03:00
|
|
|
#![feature(test)]
|
|
|
|
|
2019-12-13 09:21:25 +03:00
|
|
|
extern crate test;
|
|
|
|
|
2019-11-23 17:03:19 +03:00
|
|
|
use std::hint::black_box;
|
|
|
|
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
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn colors(b: &mut Bencher) {
|
|
|
|
// Copied from ratel-rust
|
|
|
|
bench_module(b, Default::default(), include_str!("../colors.js"))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn angular(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/angular-1.2.5.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn backbone(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/backbone-1.1.0.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery-1.9.1.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery_mobile(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/jquery.mobile-1.4.2.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn mootools(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/mootools-1.4.5.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn underscore(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/underscore-1.5.2.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn yui(b: &mut Bencher) {
|
|
|
|
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_module(b: &mut Bencher, syntax: Syntax, src: &'static str) {
|
|
|
|
b.bytes = src.len() as _;
|
|
|
|
|
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(())
|
|
|
|
});
|
|
|
|
}
|