1
+ use std:: path:: Path ;
2
+
1
3
use criterion:: { measurement:: WallTime , * } ;
2
4
use rayon:: prelude:: * ;
3
5
@@ -11,17 +13,21 @@ trait TheBencher {
11
13
12
14
fn parse ( source : & str ) -> Self :: ParseOutput ;
13
15
14
- fn bench ( g : & mut BenchmarkGroup < ' _ , WallTime > , source : & str ) {
16
+ fn id ( filename : & str ) -> String {
17
+ format ! ( "{filename}-{}" , Self :: ID )
18
+ }
19
+
20
+ fn bench ( g : & mut BenchmarkGroup < ' _ , WallTime > , filename : & str , source : & str ) {
15
21
let cpus = num_cpus:: get_physical ( ) ;
16
- let id = BenchmarkId :: new ( Self :: ID , "single-thread" ) ;
22
+ let id = BenchmarkId :: new ( Self :: id ( filename ) , "single-thread" ) ;
17
23
g. bench_with_input ( id, & source, |b, source| b. iter ( || Self :: parse ( source) ) ) ;
18
24
19
- let id = BenchmarkId :: new ( Self :: ID , "no-drop" ) ;
25
+ let id = BenchmarkId :: new ( Self :: id ( filename ) , "no-drop" ) ;
20
26
g. bench_with_input ( id, & source, |b, source| {
21
27
b. iter_with_large_drop ( || Self :: parse ( source) )
22
28
} ) ;
23
29
24
- let id = BenchmarkId :: new ( Self :: ID , "parallel" ) ;
30
+ let id = BenchmarkId :: new ( Self :: id ( filename ) , "parallel" ) ;
25
31
g. bench_with_input ( id, & source, |b, source| {
26
32
b. iter ( || {
27
33
( 0 ..cpus) . into_par_iter ( ) . for_each ( |_| {
@@ -78,14 +84,15 @@ impl TheBencher for BiomeBencher {
78
84
}
79
85
80
86
fn parser_benchmark ( c : & mut Criterion ) {
81
- let filename = "typescript.js" ;
82
- let source = std:: fs:: read_to_string ( filename) . unwrap ( ) ;
83
-
84
- let mut g = c. benchmark_group ( filename) ;
85
- OxcBencher :: bench ( & mut g, & source) ;
86
- SwcBencher :: bench ( & mut g, & source) ;
87
- BiomeBencher :: bench ( & mut g, & source) ;
88
- g. finish ( ) ;
87
+ let filenames = [ "typescript.js" , "cal.com.tsx" ] ;
88
+ for filename in filenames {
89
+ let source = std:: fs:: read_to_string ( Path :: new ( "files" ) . join ( filename) ) . unwrap ( ) ;
90
+ let mut g = c. benchmark_group ( filename) ;
91
+ OxcBencher :: bench ( & mut g, filename, & source) ;
92
+ SwcBencher :: bench ( & mut g, filename, & source) ;
93
+ BiomeBencher :: bench ( & mut g, filename, & source) ;
94
+ g. finish ( ) ;
95
+ }
89
96
}
90
97
91
98
criterion_group ! ( parser, parser_benchmark) ;
0 commit comments