Skip to content

Commit 90f5b3e

Browse files
committed
chore: add bench case for cached source
1 parent 542aef3 commit 90f5b3e

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

benches/bench.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,31 @@ fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
105105
})
106106
}
107107

108+
fn benchmark_source_for_concat_generate_string_with_cache(b: &mut Bencher) {
109+
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
110+
value: HELLOWORLD_MIN_JS,
111+
name: "helloworld.min.js",
112+
source_map: SourceMap::from_json(HELLOWORLD_MIN_JS_MAP).unwrap(),
113+
original_source: Some(HELLOWORLD_JS.to_string()),
114+
inner_source_map: Some(SourceMap::from_json(HELLOWORLD_JS_MAP).unwrap()),
115+
remove_original_source: false,
116+
});
117+
let sms_rollup = SourceMapSource::new(SourceMapSourceOptions {
118+
value: BUNDLE_JS,
119+
name: "bundle.js",
120+
source_map: SourceMap::from_json(BUNDLE_JS_MAP).unwrap(),
121+
original_source: None,
122+
inner_source_map: None,
123+
remove_original_source: false,
124+
});
125+
let concat = ConcatSource::new([sms_minify, sms_rollup]);
126+
let cached = CachedSource::new(concat);
127+
128+
b.iter(|| {
129+
cached.source();
130+
})
131+
}
132+
108133
fn benchmark_concat_generate_base64(b: &mut Bencher) {
109134
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
110135
value: HELLOWORLD_MIN_JS,
@@ -164,6 +189,31 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
164189
})
165190
}
166191

192+
fn benchmark_source_for_concat_generate_base64_with_cache(b: &mut Bencher) {
193+
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
194+
value: HELLOWORLD_MIN_JS,
195+
name: "helloworld.min.js",
196+
source_map: SourceMap::from_json(HELLOWORLD_MIN_JS_MAP).unwrap(),
197+
original_source: Some(HELLOWORLD_JS.to_string()),
198+
inner_source_map: Some(SourceMap::from_json(HELLOWORLD_JS_MAP).unwrap()),
199+
remove_original_source: false,
200+
});
201+
let sms_rollup = SourceMapSource::new(SourceMapSourceOptions {
202+
value: BUNDLE_JS,
203+
name: "bundle.js",
204+
source_map: SourceMap::from_json(BUNDLE_JS_MAP).unwrap(),
205+
original_source: None,
206+
inner_source_map: None,
207+
remove_original_source: false,
208+
});
209+
let concat = ConcatSource::new([sms_minify, sms_rollup]);
210+
let cached = CachedSource::new(concat);
211+
212+
b.iter(|| {
213+
cached.source();
214+
})
215+
}
216+
167217
fn benchmark_replace_large_minified_source(b: &mut Bencher) {
168218
let antd_minify = SourceMapSource::new(SourceMapSourceOptions {
169219
value: ANTD_MIN_JS,
@@ -278,6 +328,14 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
278328
"concat_generate_string_as_key",
279329
benchmark_concat_generate_string_as_key,
280330
);
331+
group.bench_function(
332+
"source_for_concat_generate_string_with_cache",
333+
benchmark_source_for_concat_generate_string_with_cache,
334+
);
335+
group.bench_function(
336+
"source_for_concat_generate_base64_with_cache",
337+
benchmark_source_for_concat_generate_base64_with_cache,
338+
);
281339
group.finish();
282340
}
283341

0 commit comments

Comments
 (0)