11#![ allow( missing_docs) ]
22
3+ mod bench_complex_replace_source;
4+
35use std:: collections:: HashMap ;
46
57#[ cfg( not( codspeed) ) ]
@@ -9,10 +11,12 @@ pub use criterion::*;
911pub use codspeed_criterion_compat:: * ;
1012
1113use rspack_sources:: {
12- BoxSource , CachedSource , ConcatSource , MapOptions , ReplaceSource , Source ,
13- SourceExt , SourceMap , SourceMapSource , SourceMapSourceOptions ,
14+ BoxSource , CachedSource , ConcatSource , MapOptions , Source , SourceExt ,
15+ SourceMap , SourceMapSource , SourceMapSourceOptions ,
1416} ;
1517
18+ use bench_complex_replace_source:: benchmark_complex_replace_source;
19+
1620const HELLOWORLD_JS : & str = include_str ! ( concat!(
1721 env!( "CARGO_MANIFEST_DIR" ) ,
1822 "/benches/fixtures/transpile-minify/files/helloworld.js"
@@ -164,39 +168,6 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
164168 } )
165169}
166170
167- fn benchmark_replace_large_minified_source ( b : & mut Bencher ) {
168- let antd_minify = SourceMapSource :: new ( SourceMapSourceOptions {
169- value : ANTD_MIN_JS ,
170- name : "antd.min.js" ,
171- source_map : SourceMap :: from_json ( ANTD_MIN_JS_MAP ) . unwrap ( ) ,
172- original_source : None ,
173- inner_source_map : None ,
174- remove_original_source : false ,
175- } ) ;
176- let mut replace_source = ReplaceSource :: new ( antd_minify) ;
177- replace_source. replace ( 107 , 114 , "exports" , None ) ;
178- replace_source. replace ( 130 , 143 , "'object'" , None ) ;
179- replace_source. replace ( 165 , 172 , "__webpack_require__" , None ) ;
180- replace_source. replace ( 173 , 180 , "/*! react */\" ./node_modules/.pnpm/react@18.2.0/node_modules/react/index.js\" " , None ) ;
181- replace_source. replace ( 183 , 190 , "__webpack_require__" , None ) ;
182- replace_source. replace ( 191 , 202 , "/*! react-dom */\" ./node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js\" " , None ) ;
183- replace_source. replace ( 205 , 212 , "__webpack_require__" , None ) ;
184- replace_source. replace ( 213 , 220 , "/*! dayjs */\" ./node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js\" " , None ) ;
185- replace_source. replace ( 363 , 370 , "exports" , None ) ;
186- replace_source. replace ( 373 , 385 , "exports.antd" , None ) ;
187- replace_source. replace ( 390 , 397 , "__webpack_require__" , None ) ;
188- replace_source. replace ( 398 , 405 , "/*! react */\" ./node_modules/.pnpm/react@18.2.0/node_modules/react/index.js\" " , None ) ;
189- replace_source. replace ( 408 , 415 , "__webpack_require__" , None ) ;
190- replace_source. replace ( 416 , 427 , "/*! react-dom */\" ./node_modules/.pnpm/react-dom@18.2.0_react@18.2.0/node_modules/react-dom/index.js\" " , None ) ;
191- replace_source. replace ( 430 , 437 , "__webpack_require__" , None ) ;
192- replace_source. replace ( 438 , 445 , "/*! dayjs */\" ./node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js\" " , None ) ;
193- replace_source. replace ( 494 , 498 , "this" , None ) ;
194-
195- b. iter ( || {
196- replace_source. map ( & MapOptions :: default ( ) ) ;
197- } ) ;
198- }
199-
200171fn benchmark_concat_generate_string_with_cache_as_key ( b : & mut Bencher ) {
201172 let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
202173 value : HELLOWORLD_MIN_JS ,
@@ -260,16 +231,14 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
260231 ) ;
261232 group
262233 . bench_function ( "concat_generate_base64" , benchmark_concat_generate_base64) ;
234+
263235 group. bench_function (
264236 "concat_generate_string_with_cache" ,
265237 benchmark_concat_generate_string_with_cache,
266238 ) ;
267239 group
268240 . bench_function ( "concat_generate_string" , benchmark_concat_generate_string) ;
269- group. bench_function (
270- "replace_large_minified_source" ,
271- benchmark_replace_large_minified_source,
272- ) ;
241+
273242 group. bench_function (
274243 "concat_generate_string_with_cache_as_key" ,
275244 benchmark_concat_generate_string_with_cache_as_key,
@@ -278,6 +247,10 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
278247 "concat_generate_string_as_key" ,
279248 benchmark_concat_generate_string_as_key,
280249 ) ;
250+
251+ group
252+ . bench_function ( "complex_replace_source" , benchmark_complex_replace_source) ;
253+
281254 group. finish ( ) ;
282255}
283256
0 commit comments