Skip to content

Commit b447ca5

Browse files
committed
chore: bench parse_source_map_from_json
1 parent 1004eb2 commit b447ca5

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

benches/bench.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(missing_docs)]
22

33
mod bench_complex_replace_source;
4+
mod bench_source_map;
45

56
use std::collections::HashMap;
67

@@ -16,6 +17,7 @@ use rspack_sources::{
1617
};
1718

1819
use bench_complex_replace_source::benchmark_complex_replace_source;
20+
use bench_source_map::benchmark_parse_source_map_from_json;
1921

2022
const HELLOWORLD_JS: &str = include_str!(concat!(
2123
env!("CARGO_MANIFEST_DIR"),
@@ -41,14 +43,6 @@ const BUNDLE_JS_MAP: &str = include_str!(concat!(
4143
env!("CARGO_MANIFEST_DIR"),
4244
"/benches/fixtures/transpile-rollup/files/bundle.js.map"
4345
));
44-
const ANTD_MIN_JS: &str = include_str!(concat!(
45-
env!("CARGO_MANIFEST_DIR"),
46-
"/benches/fixtures/antd-mini/antd.min.js"
47-
));
48-
const ANTD_MIN_JS_MAP: &str = include_str!(concat!(
49-
env!("CARGO_MANIFEST_DIR"),
50-
"/benches/fixtures/antd-mini/antd.min.js.map"
51-
));
5246

5347
fn benchmark_concat_generate_string(b: &mut Bencher) {
5448
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
@@ -251,6 +245,11 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
251245
group
252246
.bench_function("complex_replace_source", benchmark_complex_replace_source);
253247

248+
group.bench_function(
249+
"benchmark_parse_source_map_from_json",
250+
benchmark_parse_source_map_from_json,
251+
);
252+
254253
group.finish();
255254
}
256255

benches/bench_source_map.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(missing_docs)]
2+
3+
#[cfg(not(codspeed))]
4+
pub use criterion::*;
5+
6+
#[cfg(codspeed)]
7+
pub use codspeed_criterion_compat::*;
8+
9+
use rspack_sources::SourceMap;
10+
11+
const ANTD_MIN_JS_MAP: &str = include_str!(concat!(
12+
env!("CARGO_MANIFEST_DIR"),
13+
"/benches/fixtures/antd-mini/antd.min.js"
14+
));
15+
16+
pub fn benchmark_parse_source_map_from_json(b: &mut Bencher) {
17+
b.iter(|| {
18+
let _ = black_box(|| SourceMap::from_json(ANTD_MIN_JS_MAP).unwrap());
19+
})
20+
}

0 commit comments

Comments
 (0)