File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ use rspack_sources::{
1919use bench_complex_replace_source:: benchmark_complex_replace_source;
2020use bench_source_map:: {
2121 benchmark_parse_source_map_from_json, benchmark_source_map_clone,
22+ benchmark_stringify_source_map_to_json,
2223} ;
2324
2425const HELLOWORLD_JS : & str = include_str ! ( concat!(
@@ -254,6 +255,11 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
254255
255256 group. bench_function ( "source_map_clone" , benchmark_source_map_clone) ;
256257
258+ group. bench_function (
259+ "stringify_source_map_to_json" ,
260+ benchmark_stringify_source_map_to_json,
261+ ) ;
262+
257263 group. finish ( ) ;
258264}
259265
Original file line number Diff line number Diff line change @@ -10,18 +10,25 @@ use rspack_sources::SourceMap;
1010
1111const ANTD_MIN_JS_MAP : & str = include_str ! ( concat!(
1212 env!( "CARGO_MANIFEST_DIR" ) ,
13- "/benches/fixtures/antd-mini/antd.min.js"
13+ "/benches/fixtures/antd-mini/antd.min.js.map "
1414) ) ;
1515
1616pub fn benchmark_parse_source_map_from_json ( b : & mut Bencher ) {
1717 b. iter ( || {
18- let _ = black_box ( || SourceMap :: from_json ( ANTD_MIN_JS_MAP ) . unwrap ( ) ) ;
18+ black_box ( SourceMap :: from_json ( black_box ( ANTD_MIN_JS_MAP ) ) . unwrap ( ) )
1919 } )
2020}
2121
2222pub fn benchmark_source_map_clone ( b : & mut Bencher ) {
2323 let source = SourceMap :: from_json ( ANTD_MIN_JS_MAP ) . unwrap ( ) ;
2424 b. iter ( || {
25- let _ = black_box ( || source. clone ( ) ) ;
25+ let _ = black_box ( source. clone ( ) ) ;
26+ } )
27+ }
28+
29+ pub fn benchmark_stringify_source_map_to_json ( b : & mut Bencher ) {
30+ let source = SourceMap :: from_json ( ANTD_MIN_JS_MAP ) . unwrap ( ) ;
31+ b. iter ( || {
32+ let _ = black_box ( source. to_json ( ) . unwrap ( ) ) ;
2633 } )
2734}
Original file line number Diff line number Diff line change @@ -403,7 +403,7 @@ impl SourceMap {
403403 }
404404
405405 /// Generate source map to a json string.
406- pub fn to_json ( self ) -> Result < String > {
406+ pub fn to_json ( & self ) -> Result < String > {
407407 let json = simd_json:: serde:: to_string ( & self ) ?;
408408 Ok ( json)
409409 }
You can’t perform that action at this time.
0 commit comments