1
- #! [ feature ( test ) ]
2
- #! [ allow ( soft_unstable ) ]
1
+ #[ cfg ( not ( codspeed ) ) ]
2
+ pub use criterion :: * ;
3
3
4
- extern crate test ;
5
- use test :: Bencher ;
4
+ # [ cfg ( codspeed ) ]
5
+ pub use codspeed_criterion_compat :: * ;
6
6
7
7
use rspack_sources:: {
8
8
CachedSource , ConcatSource , MapOptions , Source , SourceMap , SourceMapSource ,
@@ -34,7 +34,6 @@ const BUNDLE_JS_MAP: &str = include_str!(concat!(
34
34
"/benches/fixtures/transpile-rollup/files/bundle.js.map"
35
35
) ) ;
36
36
37
- #[ bench]
38
37
fn benchmark_concat_generate_string ( b : & mut Bencher ) {
39
38
let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
40
39
value : HELLOWORLD_MIN_JS ,
@@ -44,6 +43,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
44
43
inner_source_map : Some ( SourceMap :: from_json ( HELLOWORLD_JS_MAP ) . unwrap ( ) ) ,
45
44
remove_original_source : false ,
46
45
} ) ;
46
+
47
47
let sms_rollup = SourceMapSource :: new ( SourceMapSourceOptions {
48
48
value : BUNDLE_JS ,
49
49
name : "bundle.js" ,
@@ -52,6 +52,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
52
52
inner_source_map : None ,
53
53
remove_original_source : false ,
54
54
} ) ;
55
+
55
56
let concat = ConcatSource :: new ( [ sms_minify, sms_rollup] ) ;
56
57
57
58
b. iter ( || {
@@ -63,7 +64,6 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
63
64
} )
64
65
}
65
66
66
- #[ bench]
67
67
fn benchmark_concat_generate_string_with_cache ( b : & mut Bencher ) {
68
68
let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
69
69
value : HELLOWORLD_MIN_JS ,
@@ -93,7 +93,6 @@ fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
93
93
} )
94
94
}
95
95
96
- #[ bench]
97
96
fn benchmark_concat_generate_base64 ( b : & mut Bencher ) {
98
97
let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
99
98
value : HELLOWORLD_MIN_JS ,
@@ -123,7 +122,6 @@ fn benchmark_concat_generate_base64(b: &mut Bencher) {
123
122
} )
124
123
}
125
124
126
- #[ bench]
127
125
fn benchmark_concat_generate_base64_with_cache ( b : & mut Bencher ) {
128
126
let sms_minify = SourceMapSource :: new ( SourceMapSourceOptions {
129
127
value : HELLOWORLD_MIN_JS ,
@@ -153,3 +151,23 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
153
151
base64_simd:: Base64 :: STANDARD . encode_to_boxed_str ( json. as_bytes ( ) ) ;
154
152
} )
155
153
}
154
+
155
+ fn bench_rspack_sources ( criterion : & mut Criterion ) {
156
+ let mut group = criterion. benchmark_group ( "rspack_sources" ) ;
157
+ group. bench_function (
158
+ "concat_generate_base64_with_cache" ,
159
+ benchmark_concat_generate_base64_with_cache,
160
+ ) ;
161
+ group
162
+ . bench_function ( "concat_generate_base64" , benchmark_concat_generate_base64) ;
163
+ group. bench_function (
164
+ "concat_generate_string_with_cache" ,
165
+ benchmark_concat_generate_string_with_cache,
166
+ ) ;
167
+ group
168
+ . bench_function ( "concat_generate_string" , benchmark_concat_generate_string) ;
169
+ group. finish ( ) ;
170
+ }
171
+
172
+ criterion_group ! ( rspack_sources, bench_rspack_sources) ;
173
+ criterion_main ! ( rspack_sources) ;
0 commit comments