@@ -12,6 +12,8 @@ const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
12
12
(can be repeated)
13
13
--exclude pattern excludes scripts matching <pattern> (can be
14
14
repeated)
15
+ --runs variable=value set the amount of benchmark suite execution.
16
+ Default: 1
15
17
--set variable=value set benchmark variable (can be repeated)
16
18
--format [simple|csv] optional value that specifies the output format
17
19
test only run a single configuration from the options
@@ -45,8 +47,7 @@ if (format === 'csv') {
45
47
console . log ( '"filename", "configuration", "rate", "time"' ) ;
46
48
}
47
49
48
- ( function recursive ( i ) {
49
- const filename = benchmarks [ i ] ;
50
+ function runBenchmark ( filename ) {
50
51
const scriptPath = path . resolve ( __dirname , filename ) ;
51
52
52
53
const args = cli . test ? [ '--test' ] : cli . optional . set ;
@@ -63,42 +64,52 @@ if (format === 'csv') {
63
64
) ;
64
65
}
65
66
66
- if ( format !== 'csv' ) {
67
- console . log ( ) ;
68
- console . log ( filename ) ;
69
- }
70
-
71
- child . on ( 'message' , ( data ) => {
72
- if ( data . type !== 'report' ) {
73
- return ;
74
- }
75
- // Construct configuration string, " A=a, B=b, ..."
76
- let conf = '' ;
77
- for ( const key of Object . keys ( data . conf ) ) {
78
- if ( conf !== '' )
79
- conf += ' ' ;
80
- conf += `${ key } =${ JSON . stringify ( data . conf [ key ] ) } ` ;
81
- }
82
- if ( format === 'csv' ) {
83
- // Escape quotes (") for correct csv formatting
84
- conf = conf . replace ( / " / g, '""' ) ;
85
- console . log ( `"${ data . name } ", "${ conf } ", ${ data . rate } , ${ data . time } ` ) ;
86
- } else {
87
- let rate = data . rate . toString ( ) . split ( '.' ) ;
88
- rate [ 0 ] = rate [ 0 ] . replace ( / ( \d ) (? = (?: \d \d \d ) + (? ! \d ) ) / g, '$1,' ) ;
89
- rate = ( rate [ 1 ] ? rate . join ( '.' ) : rate [ 0 ] ) ;
90
- console . log ( `${ data . name } ${ conf } : ${ rate } ` ) ;
91
- }
67
+ return new Promise ( ( resolve , reject ) => {
68
+ child . on ( 'message' , ( data ) => {
69
+ if ( data . type !== 'report' ) {
70
+ return ;
71
+ }
72
+ // Construct configuration string, " A=a, B=b, ..."
73
+ let conf = '' ;
74
+ for ( const key of Object . keys ( data . conf ) ) {
75
+ if ( conf !== '' )
76
+ conf += ' ' ;
77
+ conf += `${ key } =${ JSON . stringify ( data . conf [ key ] ) } ` ;
78
+ }
79
+ if ( format === 'csv' ) {
80
+ // Escape quotes (") for correct csv formatting
81
+ conf = conf . replace ( / " / g, '""' ) ;
82
+ console . log ( `"${ data . name } ", "${ conf } ", ${ data . rate } , ${ data . time } ` ) ;
83
+ } else {
84
+ let rate = data . rate . toString ( ) . split ( '.' ) ;
85
+ rate [ 0 ] = rate [ 0 ] . replace ( / ( \d ) (? = (?: \d \d \d ) + (? ! \d ) ) / g, '$1,' ) ;
86
+ rate = ( rate [ 1 ] ? rate . join ( '.' ) : rate [ 0 ] ) ;
87
+ console . log ( `${ data . name } ${ conf } : ${ rate } ` ) ;
88
+ }
89
+ } ) ;
90
+ child . once ( 'close' , ( code ) => {
91
+ if ( code ) {
92
+ reject ( code ) ;
93
+ } else {
94
+ resolve ( code ) ;
95
+ }
96
+ } ) ;
92
97
} ) ;
98
+ }
93
99
94
- child . once ( 'close' , ( code ) => {
95
- if ( code ) {
96
- process . exit ( code ) ;
100
+ async function run ( ) {
101
+ for ( let i = 0 ; i < benchmarks . length ; ++ i ) {
102
+ let runs = cli . optional . runs ?? 1 ;
103
+ const filename = benchmarks [ i ] ;
104
+ if ( format !== 'csv' ) {
105
+ console . log ( ) ;
106
+ console . log ( filename ) ;
97
107
}
98
108
99
- // If there are more benchmarks execute the next
100
- if ( i + 1 < benchmarks . length ) {
101
- recursive ( i + 1 ) ;
109
+ while ( runs -- > 0 ) {
110
+ await runBenchmark ( filename ) ;
102
111
}
103
- } ) ;
104
- } ) ( 0 ) ;
112
+ }
113
+ }
114
+
115
+ run ( ) ;
0 commit comments