@@ -43,9 +43,8 @@ class AutocannonBenchmarker {
4343 }
4444 if ( ! result || ! result . requests || ! result . requests . average ) {
4545 return undefined ;
46- } else {
47- return result . requests . average ;
4846 }
47+ return result . requests . average ;
4948 }
5049}
5150
@@ -58,10 +57,13 @@ class WrkBenchmarker {
5857 }
5958
6059 create ( options ) {
60+ const duration = typeof options . duration === 'number' ?
61+ Math . max ( options . duration , 1 ) :
62+ options . duration ;
6163 const args = [
62- '-d' , options . duration ,
64+ '-d' , duration ,
6365 '-c' , options . connections ,
64- '-t' , 8 ,
66+ '-t' , Math . min ( options . connections , require ( 'os' ) . cpus ( ) . length || 8 ) ,
6567 `http://127.0.0.1:${ options . port } ${ options . path } ` ,
6668 ] ;
6769 for ( const field in options . headers ) {
@@ -77,9 +79,8 @@ class WrkBenchmarker {
7779 const throughput = match && + match [ 1 ] ;
7880 if ( ! isFinite ( throughput ) ) {
7981 return undefined ;
80- } else {
81- return throughput ;
8282 }
83+ return throughput ;
8384 }
8485}
8586
@@ -89,18 +90,21 @@ class WrkBenchmarker {
8990 */
9091class TestDoubleBenchmarker {
9192 constructor ( type ) {
92- // `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
93+ // `type` is the type of benchmarker. Possible values are 'http' and
94+ // 'http2'.
9395 this . name = `test-double-${ type } ` ;
9496 this . executable = path . resolve ( __dirname , '_test-double-benchmarker.js' ) ;
9597 this . present = fs . existsSync ( this . executable ) ;
9698 this . type = type ;
9799 }
98100
99101 create ( options ) {
100- const env = Object . assign ( {
101- duration : options . duration ,
102+ process . env . duration = process . env . duration || options . duration || 5 ;
103+
104+ const env = {
102105 test_url : `http://127.0.0.1:${ options . port } ${ options . path } ` ,
103- } , process . env ) ;
106+ ...process . env
107+ } ;
104108
105109 const child = child_process . fork ( this . executable ,
106110 [ this . type ] ,
@@ -189,13 +193,14 @@ http_benchmarkers.forEach((benchmarker) => {
189193} ) ;
190194
191195exports . run = function ( options , callback ) {
192- options = Object . assign ( {
196+ options = {
193197 port : exports . PORT ,
194198 path : '/' ,
195199 connections : 100 ,
196200 duration : 5 ,
197201 benchmarker : exports . default_http_benchmarker ,
198- } , options ) ;
202+ ...options
203+ } ;
199204 if ( ! options . benchmarker ) {
200205 callback ( new Error ( 'Could not locate required http benchmarker. See ' +
201206 `${ requirementsURL } for further instructions.` ) ) ;
@@ -220,7 +225,8 @@ exports.run = function(options, callback) {
220225 child . stderr . pipe ( process . stderr ) ;
221226
222227 let stdout = '' ;
223- child . stdout . on ( 'data' , ( chunk ) => stdout += chunk . toString ( ) ) ;
228+ child . stdout . setEncoding ( 'utf8' ) ;
229+ child . stdout . on ( 'data' , ( chunk ) => stdout += chunk ) ;
224230
225231 child . once ( 'close' , ( code ) => {
226232 const elapsed = process . hrtime ( benchmarker_start ) ;
0 commit comments