Skip to content

Commit

Permalink
chore: add bench case for cached source
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 16, 2024
1 parent 542aef3 commit da072e5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ fn benchmark_replace_large_minified_source(b: &mut Bencher) {
});
}

fn benchmark_source_for_replace_large_minified_source_with_cache(b: &mut Bencher) {
let antd_minify = SourceMapSource::new(SourceMapSourceOptions {
value: ANTD_MIN_JS,
name: "antd.min.js",
source_map: SourceMap::from_json(ANTD_MIN_JS_MAP).unwrap(),
original_source: None,
inner_source_map: None,
remove_original_source: false,
});
let mut replace_source = ReplaceSource::new(antd_minify);
replace_source.replace(107, 114, "exports", None);
replace_source.replace(130, 143, "'object'", None);
replace_source.replace(165, 172, "__webpack_require__", None);
replace_source.replace(173, 180, "/*! react */\"./node_modules/.pnpm/[email protected]/node_modules/react/index.js\"", None);
replace_source.replace(183, 190, "__webpack_require__", None);
replace_source.replace(191, 202, "/*! react-dom */\"./node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js\"", None);
replace_source.replace(205, 212, "__webpack_require__", None);
replace_source.replace(213, 220, "/*! dayjs */\"./node_modules/.pnpm/[email protected]/node_modules/dayjs/dayjs.min.js\"", None);
replace_source.replace(363, 370, "exports", None);
replace_source.replace(373, 385, "exports.antd", None);
replace_source.replace(390, 397, "__webpack_require__", None);
replace_source.replace(398, 405, "/*! react */\"./node_modules/.pnpm/[email protected]/node_modules/react/index.js\"", None);
replace_source.replace(408, 415, "__webpack_require__", None);
replace_source.replace(416, 427, "/*! react-dom */\"./node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/index.js\"", None);
replace_source.replace(430, 437, "__webpack_require__", None);
replace_source.replace(438, 445, "/*! dayjs */\"./node_modules/.pnpm/[email protected]/node_modules/dayjs/dayjs.min.js\"", None);
replace_source.replace(494, 498, "this", None);

let cached = CachedSource::new(replace_source.boxed());

b.iter(|| {
cached.source();
});
}

fn benchmark_concat_generate_string_with_cache_as_key(b: &mut Bencher) {
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
value: HELLOWORLD_MIN_JS,
Expand Down Expand Up @@ -278,6 +313,10 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
"concat_generate_string_as_key",
benchmark_concat_generate_string_as_key,
);
group.bench_function(
"source_for_replace_large_minified_source_with_cache",
benchmark_source_for_replace_large_minified_source_with_cache,
);
group.finish();
}

Expand Down

0 comments on commit da072e5

Please sign in to comment.