summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJohan Bergström <bugs@bergstroem.nu>2015-02-27 13:37:46 +1100
committerRod Vagg <rod@vagg.org>2015-03-04 20:25:49 -0800
commit2b79052494e6ec6d715f6e856df0f1503baa0a75 (patch)
tree7d138e6899778ae681eecc34c7562e855f2f5907 /benchmark
parenta45d4f8fd61c05c98d6f723ec14d4a7285de5256 (diff)
downloadnode-new-2b79052494e6ec6d715f6e856df0f1503baa0a75.tar.gz
benchmark: check for wrk ahead of running benchmarks
PR-URL: https://github.com/iojs/io.js/pull/982 Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/README.md8
-rw-r--r--benchmark/common.js21
2 files changed, 23 insertions, 6 deletions
diff --git a/benchmark/README.md b/benchmark/README.md
index 0568f35029..dc6f53fbe7 100644
--- a/benchmark/README.md
+++ b/benchmark/README.md
@@ -3,9 +3,13 @@
This folder contains benchmark tests to measure the performance for certain
io.js APIs.
-## prerequisites
+## Prerequisites
-Most of the http benchmarks require `wrk` and `ab` being installed.
+Most of the http benchmarks require [`wrk`][wrk] and [`ab`][ab] being installed.
+These are most often available through your preferred package manager.
+
+[wrk]: https://github.com/wg/wrk
+[ab]: http://httpd.apache.org/docs/2.2/programs/ab.html
## How to run tests
diff --git a/benchmark/common.js b/benchmark/common.js
index 2e3cedced3..0b0c7ee870 100644
--- a/benchmark/common.js
+++ b/benchmark/common.js
@@ -1,7 +1,7 @@
var assert = require('assert');
var fs = require('fs');
var path = require('path');
-var spawn = require('child_process').spawn;
+var child_process = require('child_process');
var silent = +process.env.NODE_BENCH_SILENT;
@@ -9,6 +9,7 @@ exports.PORT = process.env.PORT || 12346;
// If this is the main module, then run the benchmarks
if (module === require.main) {
+ hasWrk();
var type = process.argv[2];
var testFilter = process.argv[3];
if (!type) {
@@ -36,6 +37,15 @@ if (module === require.main) {
runBenchmarks();
}
+function hasWrk() {
+ var result = child_process.spawnSync('wrk', ['-h']);
+ if (result.error.code === 'ENOENT') {
+ console.error('Couldn\'t locate `wrk` which is needed for running ' +
+ 'benchmarks. Check benchmark/README.md for further instructions.');
+ process.exit(-1);
+ }
+}
+
function runBenchmarks() {
var test = tests.shift();
if (!test)
@@ -48,7 +58,7 @@ function runBenchmarks() {
test = path.resolve(dir, test);
var a = (process.execArgv || []).concat(test);
- var child = spawn(process.execPath, a, { stdio: 'inherit' });
+ var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
child.on('close', function(code) {
if (code) {
process.exit(code);
@@ -70,7 +80,10 @@ function Benchmark(fn, options) {
this._name = require.main.filename.split(/benchmark[\/\\]/).pop();
this._start = [0,0];
this._started = false;
+
var self = this;
+
+ hasWrk();
process.nextTick(function() {
self._run();
});
@@ -85,7 +98,7 @@ Benchmark.prototype.http = function(p, args, cb) {
args = args.concat(url);
var out = '';
- var child = spawn('wrk', args);
+ var child = child_process.spawn('wrk', args);
child.stdout.setEncoding('utf8');
@@ -145,7 +158,7 @@ Benchmark.prototype._run = function() {
if (!argv)
return;
argv = process.execArgv.concat(argv);
- var child = spawn(node, argv, { stdio: 'inherit' });
+ var child = child_process.spawn(node, argv, { stdio: 'inherit' });
child.on('close', function(code, signal) {
if (code)
console.error('child process exited with code ' + code);