@@ -8,26 +8,34 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
88
99trait TheBencher {
1010 type RunOutput ;
11+ type Options : Send + Sync ;
1112
1213 const ID : & ' static str ;
1314
14- fn run ( path : & Path , source : & str ) -> Self :: RunOutput ;
15+ fn run ( path : & Path , source : & str , options : & Self :: Options ) -> Self :: RunOutput ;
1516
16- fn bench ( g : & mut BenchmarkGroup < ' _ , WallTime > , path : & Path , source : & str ) {
17+ fn bench (
18+ g : & mut BenchmarkGroup < ' _ , WallTime > ,
19+ path : & Path ,
20+ source : & str ,
21+ options : & Self :: Options ,
22+ ) {
1723 let cpus = num_cpus:: get_physical ( ) ;
1824 let id = BenchmarkId :: new ( Self :: ID , "single-thread" ) ;
19- g. bench_with_input ( id, & source, |b, source| b. iter ( || Self :: run ( path, source) ) ) ;
25+ g. bench_with_input ( id, & source, |b, source| {
26+ b. iter ( || Self :: run ( path, source, options) )
27+ } ) ;
2028
2129 let id = BenchmarkId :: new ( Self :: ID , "no-drop" ) ;
2230 g. bench_with_input ( id, & source, |b, source| {
23- b. iter_with_large_drop ( || Self :: run ( path, source) )
31+ b. iter_with_large_drop ( || Self :: run ( path, source, options ) )
2432 } ) ;
2533
2634 let id = BenchmarkId :: new ( Self :: ID , "parallel" ) ;
2735 g. bench_with_input ( id, & source, |b, source| {
2836 b. iter ( || {
2937 ( 0 ..cpus) . into_par_iter ( ) . for_each ( |_| {
30- Self :: run ( path, source) ;
38+ Self :: run ( path, source, options ) ;
3139 } ) ;
3240 } )
3341 } ) ;
@@ -38,22 +46,24 @@ struct OxcBencher;
3846
3947impl TheBencher for OxcBencher {
4048 type RunOutput = ( oxc:: allocator:: Allocator , String ) ;
49+ type Options = oxc:: transformer:: TransformOptions ;
4150
4251 const ID : & ' static str = "oxc" ;
4352
44- fn run ( path : & Path , source_text : & str ) -> Self :: RunOutput {
45- bench_transformer:: oxc:: transform ( path, source_text)
53+ fn run ( path : & Path , source_text : & str , options : & Self :: Options ) -> Self :: RunOutput {
54+ bench_transformer:: oxc:: transform ( path, source_text, options )
4655 }
4756}
4857
4958struct SwcBencher ;
5059
5160impl TheBencher for SwcBencher {
5261 type RunOutput = String ;
62+ type Options = ( ) ;
5363
5464 const ID : & ' static str = "swc" ;
5565
56- fn run ( path : & Path , source_text : & str ) -> Self :: RunOutput {
66+ fn run ( path : & Path , source_text : & str , _option : & Self :: Options ) -> Self :: RunOutput {
5767 bench_transformer:: swc:: transform ( path, source_text)
5868 }
5969}
@@ -64,8 +74,11 @@ fn transformer_benchmark(c: &mut Criterion) {
6474 let path = Path :: new ( "files" ) . join ( filename) ;
6575 let source = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
6676 let mut g = c. benchmark_group ( filename) ;
67- OxcBencher :: bench ( & mut g, & path, & source) ;
68- SwcBencher :: bench ( & mut g, & path, & source) ;
77+
78+ let options = oxc:: transformer:: TransformOptions :: from_target ( "es2015" ) . unwrap ( ) ;
79+ OxcBencher :: bench ( & mut g, & path, & source, & options) ;
80+
81+ SwcBencher :: bench ( & mut g, & path, & source, & ( ) ) ;
6982 g. finish ( ) ;
7083 }
7184}
0 commit comments