1+ "use strict" ;
2+
13var fs = require ( "fs" ) ,
24 path = require ( "path" ) ;
35
46// A profiling stub to measure encoding / decoding performance using benchmark data.
57
68var commands = [ "encode" , "decode" , "encode-browser" , "decode-browser" ] ;
79if ( commands . indexOf ( process . argv [ 2 ] ) < 0 ) { // 0: node, 1: prof.js
8- console . error ( "usage: " + path . basename ( process . argv [ 1 ] ) + " <" + commands . join ( '|' ) + "> [iterations=10000000]" ) ;
9- process . exit ( 0 ) ;
10+ process . stderr . write ( "usage: " + path . basename ( process . argv [ 1 ] ) + " <" + commands . join ( "|" ) + "> [iterations=10000000]\n " ) ;
11+ return ;
1012}
1113
1214// Spin up a node process with profiling enabled and process the generated log
1315if ( process . execArgv . indexOf ( "--prof" ) < 0 ) {
14- console . log ( "cleaning up old logs ..." ) ;
16+ process . stdout . write ( "cleaning up old logs ...\n " ) ;
1517 var child_process = require ( "child_process" ) ;
16- var logRe = / ^ i s o l a t e \ -[ 0 - 9 A - F ] + \ -v 8 \. l o g $ / ;
18+ var logRe = / ^ i s o l a t e - [ 0 - 9 A - F ] + - v 8 \. l o g $ / ;
1719 fs . readdirSync ( process . cwd ( ) ) . forEach ( function readdirSync_it ( file ) {
1820 if ( logRe . test ( file ) )
1921 fs . unlink ( file ) ;
2022 } ) ;
21- console . log ( "generating profile (may take a while) ..." ) ;
22- var child = child_process . execSync ( "node --prof --trace-deopt " + process . execArgv . join ( " " ) + " " + process . argv . slice ( 1 ) . join ( ' ' ) , {
23+ process . stdout . write ( "generating profile (may take a while) ...\n " ) ;
24+ child_process . execSync ( "node --prof --trace-deopt " + process . execArgv . join ( " " ) + " " + process . argv . slice ( 1 ) . join ( ' ' ) , {
2325 cwd : process . cwd ( ) ,
24- stdio : ' inherit'
26+ stdio : " inherit"
2527 } ) ;
26- console . log ( "processing profile ..." ) ;
28+ process . stdout . write ( "processing profile ...\n " ) ;
2729 fs . readdirSync ( process . cwd ( ) ) . forEach ( function readdirSync_it ( file ) {
2830 if ( logRe . test ( file ) ) {
2931 child_process . execSync ( "node --prof-process " + file , {
3032 cwd : process . cwd ( ) ,
31- stdio : ' inherit'
33+ stdio : " inherit"
3234 } ) ;
3335 // fs.unlink(file);
3436 }
3537 } ) ;
36- console . log ( "done." ) ;
37- process . exit ( 0 ) ;
38+ process . stdout . write ( "done.\n " ) ;
39+ return ;
3840}
3941
4042// Actual profiling code
@@ -59,7 +61,7 @@ if (process.argv.indexOf("--alt") < 0) {
5961
6062if ( process . argv . length > 3 && / ^ \d + $ / . test ( process . argv [ 3 ] ) )
6163 count = parseInt ( process . argv [ 3 ] , 10 ) ;
62- console . log ( " x " + count ) ;
64+ process . stdout . write ( " x " + count + "\n" ) ;
6365
6466function setupBrowser ( ) {
6567 protobuf . Writer . create = function create_browser ( ) { return new protobuf . Writer ( ) ; } ;
@@ -69,16 +71,17 @@ function setupBrowser() {
6971switch ( process . argv [ 2 ] ) {
7072 case "encode-browser" :
7173 setupBrowser ( ) ;
74+ // eslint-disable-line no-fallthrough
7275 case "encode" :
7376 for ( var i = 0 ; i < count ; ++ i )
7477 Test . encode ( data ) . finish ( ) ;
7578 break ;
7679 case "decode-browser" :
7780 setupBrowser ( ) ;
81+ // eslint-disable-line no-fallthrough
7882 case "decode" :
7983 var buf = Test . encode ( data ) . finish ( ) ;
80- for ( var i = 0 ; i < count ; ++ i )
84+ for ( var j = 0 ; j < count ; ++ j )
8185 Test . decode ( buf ) ;
8286 break ;
8387}
84- process . exit ( 0 ) ;
0 commit comments