mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
d1097ccb59
**Description:** For now, we leave every comment as a leading comment. As logic for determining leading vs trailing is quite complex, I'll do it with another PR.
52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
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, parser::Parser};
|
|
|
|
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 _ = black_box({
|
|
let lexer = Lexer::new(StringInput::from(&*fm), None, Default::default());
|
|
let mut parser = Parser::new(lexer, Default::default());
|
|
|
|
parser.parse_all()
|
|
});
|
|
});
|
|
|
|
Ok(())
|
|
});
|
|
}
|
|
|
|
fn run(c: &mut Criterion, id: &str, src: &'static str) {
|
|
c.bench_function(&format!("css/parser/{}", id), |b| {
|
|
bench_stylesheet(b, src);
|
|
});
|
|
}
|
|
|
|
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"),
|
|
);
|
|
}
|
|
|
|
criterion_group!(benches, bench_files);
|
|
criterion_main!(benches);
|