2022-06-11 17:47:08 +03:00
|
|
|
extern crate swc_node_base;
|
|
|
|
|
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
|
|
|
|
use swc_common::{input::StringInput, FileName};
|
|
|
|
use swc_css_parser::lexer::Lexer;
|
|
|
|
|
|
|
|
fn bench_stylesheet(b: &mut Bencher, src: &'static str) {
|
|
|
|
let _ = ::testing::run_test(false, |cm, _| {
|
|
|
|
let fm = cm.new_source_file(FileName::Anon, src.into());
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
let lexer = Lexer::new(StringInput::from(&*fm), Default::default());
|
|
|
|
|
|
|
|
for t in lexer {
|
|
|
|
black_box(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:27:45 +03:00
|
|
|
fn run(c: &mut Criterion, id: &str, src: &'static str) {
|
2022-12-07 03:59:29 +03:00
|
|
|
c.bench_function(&format!("css/lexer/{}", id), |b| {
|
2022-12-06 17:27:45 +03:00
|
|
|
bench_stylesheet(b, src);
|
2022-06-11 17:47:08 +03:00
|
|
|
});
|
2022-12-06 17:27:45 +03:00
|
|
|
}
|
2022-06-11 17:47:08 +03:00
|
|
|
|
2022-12-06 17:27:45 +03:00
|
|
|
fn bench_files(c: &mut Criterion) {
|
|
|
|
run(
|
|
|
|
c,
|
|
|
|
"bootstrap_5_1_3",
|
|
|
|
include_str!("./files/bootstrap_5_1_3.css"),
|
|
|
|
);
|
|
|
|
|
|
|
|
run(
|
|
|
|
c,
|
|
|
|
"foundation_6_7_4",
|
|
|
|
include_str!("./files/foundation_6_7_4.css"),
|
|
|
|
);
|
|
|
|
|
|
|
|
run(
|
|
|
|
c,
|
|
|
|
"tailwind_3_1_1",
|
|
|
|
include_str!("./files/tailwind_3_1_1.css"),
|
|
|
|
);
|
2022-06-11 17:47:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_files);
|
|
|
|
criterion_main!(benches);
|