33
44use std:: sync:: Arc ;
55
6- use rspack:: builder:: Builder as _;
6+ use rspack:: builder:: { Builder as _, Devtool } ;
77use rspack_benchmark:: { criterion_group, criterion_main, Criterion } ;
88use rspack_core:: Compiler ;
99use rspack_fs:: { MemoryFileSystem , ReadableFileSystem , WritableFileSystem } ;
@@ -12,15 +12,23 @@ use tokio::runtime::Builder;
1212trait FileSystem : ReadableFileSystem + WritableFileSystem + Send + Sync { }
1313impl < T : ReadableFileSystem + WritableFileSystem + Send + Sync > FileSystem for T { }
1414
15- async fn basic ( fs : Arc < dyn FileSystem > ) {
16- let mut compiler = Compiler :: builder ( )
15+ async fn basic ( fs : Arc < dyn FileSystem > , sm : bool ) {
16+ let mut builder = Compiler :: builder ( ) ;
17+
18+ builder
1719 . context ( "/" )
1820 . entry ( "main" , "./src/index.js" )
1921 . input_filesystem ( fs. clone ( ) )
20- . output_filesystem ( fs. clone ( ) )
21- . build ( ) ;
22+ . output_filesystem ( fs. clone ( ) ) ;
23+
24+ if sm {
25+ builder. devtool ( Devtool :: SourceMap ) ;
26+ }
27+
28+ let mut compiler = builder. build ( ) ;
2229
2330 compiler. run ( ) . await . unwrap ( ) ;
31+
2432 assert ! ( compiler
2533 . compilation
2634 . get_errors( )
@@ -29,28 +37,36 @@ async fn basic(fs: Arc<dyn FileSystem>) {
2937}
3038
3139pub fn criterion_benchmark ( c : & mut Criterion ) {
40+ let rt = Builder :: new_multi_thread ( ) . build ( ) . unwrap ( ) ;
41+
42+ let fs = MemoryFileSystem :: default ( ) ;
43+ rt. block_on ( async {
44+ fs. create_dir_all ( "/src" . into ( ) ) . await . unwrap ( ) ;
45+ fs. write (
46+ "/src/index.js" . into ( ) ,
47+ br#"if(process.env.NODE_ENV === "production") {
48+ console.log(123);
49+ } else {
50+ console.log(456);
51+ }
52+ "# ,
53+ )
54+ . await
55+ . unwrap ( ) ;
56+ } ) ;
57+ let fs = Arc :: new ( fs) ;
58+
3259 c. bench_function ( "basic" , |b| {
33- let rt = Builder :: new_multi_thread ( ) . build ( ) . unwrap ( ) ;
34-
35- let fs = MemoryFileSystem :: default ( ) ;
36- rt. block_on ( async {
37- fs. create_dir_all ( "/src" . into ( ) ) . await . unwrap ( ) ;
38- fs. write (
39- "/src/index.js" . into ( ) ,
40- br#"if(process.env.NODE_ENV === "production") {
41- console.log(123);
42- } else {
43- console.log(456);
44- }
45- "# ,
46- )
47- . await
48- . unwrap ( ) ;
60+ b. to_async ( & rt) . iter ( || {
61+ let fs = fs. clone ( ) ;
62+ basic ( fs, false )
4963 } ) ;
50- let fs = Arc :: new ( fs) ;
64+ } ) ;
65+
66+ c. bench_function ( "basic_sourcemap" , |b| {
5167 b. to_async ( & rt) . iter ( || {
5268 let fs = fs. clone ( ) ;
53- basic ( fs)
69+ basic ( fs, true )
5470 } ) ;
5571 } ) ;
5672}
0 commit comments