2018-11-17 04:02:40 +03:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate swc_common;
|
|
|
|
extern crate swc_ecma_parser;
|
|
|
|
extern crate test;
|
|
|
|
extern crate testing;
|
|
|
|
|
|
|
|
use swc_common::FileName;
|
|
|
|
use swc_ecma_parser::{Parser, Session, SourceFileInput};
|
|
|
|
use test::Bencher;
|
|
|
|
|
2018-12-21 10:54:36 +03:00
|
|
|
#[bench]
|
|
|
|
fn colors(b: &mut Bencher) {
|
|
|
|
// Copied from ratel-rust
|
|
|
|
bench_module(b, include_str!("../colors.js"))
|
2018-11-17 04:02:40 +03:00
|
|
|
}
|
2018-12-21 10:54:36 +03:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn angular(b: &mut Bencher) {
|
|
|
|
bench_module(b, include_str!("./esprima/test/3rdparty/angular-1.2.5.js"))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn backbone(b: &mut Bencher) {
|
|
|
|
bench_module(b, include_str!("./esprima/test/3rdparty/backbone-1.1.0.js"))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery(b: &mut Bencher) {
|
|
|
|
bench_module(b, include_str!("./esprima/test/3rdparty/jquery-1.9.1.js"))
|
2018-11-17 04:02:40 +03:00
|
|
|
}
|
2018-12-21 10:54:36 +03:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery_mobile(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
include_str!("./esprima/test/3rdparty/jquery.mobile-1.4.2.js"),
|
|
|
|
)
|
2018-11-17 04:02:40 +03:00
|
|
|
}
|
2018-12-21 10:54:36 +03:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn mootools(b: &mut Bencher) {
|
|
|
|
bench_module(b, include_str!("./esprima/test/3rdparty/mootools-1.4.5.js"))
|
2018-11-17 04:02:40 +03:00
|
|
|
}
|
2018-12-21 10:54:36 +03:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn underscore(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
include_str!("./esprima/test/3rdparty/underscore-1.5.2.js"),
|
|
|
|
)
|
2018-11-17 04:02:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2018-12-21 10:54:36 +03:00
|
|
|
fn yui(b: &mut Bencher) {
|
|
|
|
bench_module(b, include_str!("./esprima/test/3rdparty/yui-3.12.0.js"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_module(b: &mut Bencher, src: &'static str) {
|
|
|
|
b.bytes = src.len() as _;
|
|
|
|
|
|
|
|
let _ = ::testing::run_test(|cm, handler| {
|
|
|
|
let session = Session {
|
|
|
|
handler: &handler,
|
|
|
|
cfg: Default::default(),
|
|
|
|
};
|
|
|
|
let fm = cm.new_source_file(FileName::Anon(0), src.into());
|
2018-11-17 04:02:40 +03:00
|
|
|
|
2018-12-01 16:24:26 +03:00
|
|
|
b.iter(|| {
|
|
|
|
test::black_box({
|
2018-12-21 10:54:36 +03:00
|
|
|
let mut parser = Parser::new(session, SourceFileInput::from(&*fm));
|
2018-12-01 16:24:26 +03:00
|
|
|
let _ = parser.parse_module();
|
|
|
|
})
|
|
|
|
});
|
2018-11-17 04:02:40 +03:00
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
}
|