@@ -10,31 +10,54 @@ const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
10
10
11
11
--filter pattern string to filter benchmark scripts
12
12
--set variable=value set benchmark variable (can be repeated)
13
+ --format [simple|csv] optional value that specifies the output format
13
14
` , {
14
15
arrayArgs : [ 'set' ]
15
16
} ) ;
16
17
const benchmarks = cli . benchmarks ( ) ;
17
18
18
19
if ( benchmarks . length === 0 ) {
19
- console . error ( 'no benchmarks found' ) ;
20
- process . exit ( 1 ) ;
20
+ console . error ( 'No benchmarks found' ) ;
21
+ process . exitCode = 1 ;
22
+ return ;
23
+ }
24
+
25
+ const validFormats = [ 'csv' , 'simple' ] ;
26
+ const format = cli . optional . format || 'simple' ;
27
+ if ( ! validFormats . includes ( format ) ) {
28
+ console . error ( 'Invalid format detected' ) ;
29
+ process . exitCode = 1 ;
30
+ return ;
31
+ }
32
+
33
+ if ( format === 'csv' ) {
34
+ console . log ( '"filename", "configuration", "rate", "time"' ) ;
21
35
}
22
36
23
37
( function recursive ( i ) {
24
38
const filename = benchmarks [ i ] ;
25
39
const child = fork ( path . resolve ( __dirname , filename ) , cli . optional . set ) ;
26
40
27
- console . log ( ) ;
28
- console . log ( filename ) ;
41
+ if ( format !== 'csv' ) {
42
+ console . log ( ) ;
43
+ console . log ( filename ) ;
44
+ }
29
45
30
46
child . on ( 'message' , function ( data ) {
31
47
// Construct configuration string, " A=a, B=b, ..."
32
48
let conf = '' ;
33
49
for ( const key of Object . keys ( data . conf ) ) {
34
50
conf += ' ' + key + '=' + JSON . stringify ( data . conf [ key ] ) ;
35
51
}
36
-
37
- console . log ( `${ data . name } ${ conf } : ${ data . rate } ` ) ;
52
+ // delete first space of the configuration
53
+ conf = conf . slice ( 1 ) ;
54
+ if ( format === 'csv' ) {
55
+ // Escape quotes (") for correct csv formatting
56
+ conf = conf . replace ( / " / g, '""' ) ;
57
+ console . log ( `"${ data . name } ", "${ conf } ", ${ data . rate } , ${ data . time } ` ) ;
58
+ } else {
59
+ console . log ( `${ data . name } ${ conf } : ${ data . rate } ` ) ;
60
+ }
38
61
} ) ;
39
62
40
63
child . once ( 'close' , function ( code ) {
0 commit comments