2018-11-17 04:02:40 +03:00
|
|
|
#![feature(test)]
|
|
|
|
|
2019-12-13 09:21:25 +03:00
|
|
|
extern crate test;
|
|
|
|
|
2018-11-17 04:02:40 +03:00
|
|
|
use swc_common::FileName;
|
2019-12-14 12:51:08 +03:00
|
|
|
use swc_ecma_parser::{lexer::Lexer, Parser, Session, SourceFileInput, Syntax};
|
2018-11-17 04:02:40 +03:00
|
|
|
use test::Bencher;
|
|
|
|
|
2018-12-21 10:54:36 +03:00
|
|
|
#[bench]
|
|
|
|
fn colors(b: &mut Bencher) {
|
|
|
|
// Copied from ratel-rust
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(b, Default::default(), 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) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/angular-1.2.5.js"),
|
|
|
|
)
|
2018-12-21 10:54:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn backbone(b: &mut Bencher) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/backbone-1.1.0.js"),
|
|
|
|
)
|
2018-12-21 10:54:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery(b: &mut Bencher) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/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) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/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) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/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) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Default::default(),
|
|
|
|
include_str!("./files/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) {
|
2019-11-22 15:13:14 +03:00
|
|
|
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
|
2018-12-21 10:54:36 +03:00
|
|
|
}
|
|
|
|
|
2019-11-22 15:13:14 +03:00
|
|
|
#[bench]
|
|
|
|
fn colors_ts(b: &mut Bencher) {
|
|
|
|
// Copied from ratel-rust
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("../colors.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn angular_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/angular-1.2.5.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn backbone_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/backbone-1.1.0.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/jquery-1.9.1.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn jquery_mobile_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/jquery.mobile-1.4.2.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn mootools_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/mootools-1.4.5.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn underscore_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/underscore-1.5.2.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn yui_ts(b: &mut Bencher) {
|
|
|
|
bench_module(
|
|
|
|
b,
|
|
|
|
Syntax::Typescript(Default::default()),
|
|
|
|
include_str!("./files/yui-3.12.0.js"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_module(b: &mut Bencher, syntax: Syntax, src: &'static str) {
|
2018-12-21 10:54:36 +03:00
|
|
|
b.bytes = src.len() as _;
|
|
|
|
|
2019-01-07 13:43:47 +03:00
|
|
|
let _ = ::testing::run_test(false, |cm, handler| {
|
|
|
|
let session = Session { handler: &handler };
|
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(|| {
|
2019-02-08 07:00:58 +03:00
|
|
|
let _ = test::black_box({
|
2019-12-14 12:51:08 +03:00
|
|
|
let lexer = Lexer::new(
|
|
|
|
session,
|
|
|
|
syntax,
|
|
|
|
Default::default(),
|
|
|
|
SourceFileInput::from(&*fm),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
let mut parser = Parser::new_from(session, 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(())
|
|
|
|
});
|
|
|
|
}
|