1
1
var assert = require ( 'assert' ) ;
2
2
var fs = require ( 'fs' ) ;
3
3
var path = require ( 'path' ) ;
4
- var spawn = require ( 'child_process' ) . spawn ;
4
+ var child_process = require ( 'child_process' ) ;
5
5
6
6
var silent = + process . env . NODE_BENCH_SILENT ;
7
7
8
8
exports . PORT = process . env . PORT || 12346 ;
9
9
10
10
// If this is the main module, then run the benchmarks
11
11
if ( module === require . main ) {
12
+ hasWrk ( ) ;
12
13
var type = process . argv [ 2 ] ;
13
14
var testFilter = process . argv [ 3 ] ;
14
15
if ( ! type ) {
@@ -36,6 +37,15 @@ if (module === require.main) {
36
37
runBenchmarks ( ) ;
37
38
}
38
39
40
+ function hasWrk ( ) {
41
+ var result = child_process . spawnSync ( 'wrk' , [ '-h' ] ) ;
42
+ if ( result . error . code === 'ENOENT' ) {
43
+ console . error ( 'Couldn\'t locate `wrk` which is needed for running ' +
44
+ 'benchmarks. Check benchmark/README.md for further instructions.' ) ;
45
+ process . exit ( - 1 ) ;
46
+ }
47
+ }
48
+
39
49
function runBenchmarks ( ) {
40
50
var test = tests . shift ( ) ;
41
51
if ( ! test )
@@ -48,7 +58,7 @@ function runBenchmarks() {
48
58
test = path . resolve ( dir , test ) ;
49
59
50
60
var a = ( process . execArgv || [ ] ) . concat ( test ) ;
51
- var child = spawn ( process . execPath , a , { stdio : 'inherit' } ) ;
61
+ var child = child_process . spawn ( process . execPath , a , { stdio : 'inherit' } ) ;
52
62
child . on ( 'close' , function ( code ) {
53
63
if ( code ) {
54
64
process . exit ( code ) ;
@@ -70,7 +80,10 @@ function Benchmark(fn, options) {
70
80
this . _name = require . main . filename . split ( / b e n c h m a r k [ \/ \\ ] / ) . pop ( ) ;
71
81
this . _start = [ 0 , 0 ] ;
72
82
this . _started = false ;
83
+
73
84
var self = this ;
85
+
86
+ hasWrk ( ) ;
74
87
process . nextTick ( function ( ) {
75
88
self . _run ( ) ;
76
89
} ) ;
@@ -85,7 +98,7 @@ Benchmark.prototype.http = function(p, args, cb) {
85
98
args = args . concat ( url ) ;
86
99
87
100
var out = '' ;
88
- var child = spawn ( 'wrk' , args ) ;
101
+ var child = child_process . spawn ( 'wrk' , args ) ;
89
102
90
103
child . stdout . setEncoding ( 'utf8' ) ;
91
104
@@ -145,7 +158,7 @@ Benchmark.prototype._run = function() {
145
158
if ( ! argv )
146
159
return ;
147
160
argv = process . execArgv . concat ( argv ) ;
148
- var child = spawn ( node , argv , { stdio : 'inherit' } ) ;
161
+ var child = child_process . spawn ( node , argv , { stdio : 'inherit' } ) ;
149
162
child . on ( 'close' , function ( code , signal ) {
150
163
if ( code )
151
164
console . error ( 'child process exited with code ' + code ) ;
0 commit comments