diff --git a/Makefile b/Makefile index 1205d1a6a2833a..c8279682cc7af4 100644 --- a/Makefile +++ b/Makefile @@ -627,41 +627,41 @@ ifneq ($(haswrk), 0) endif bench-net: all - @$(NODE) benchmark/common.js net + @$(NODE) benchmark/run.js net bench-crypto: all - @$(NODE) benchmark/common.js crypto + @$(NODE) benchmark/run.js crypto bench-tls: all - @$(NODE) benchmark/common.js tls + @$(NODE) benchmark/run.js tls bench-http: wrk all - @$(NODE) benchmark/common.js http + @$(NODE) benchmark/run.js http bench-fs: all - @$(NODE) benchmark/common.js fs + @$(NODE) benchmark/run.js fs bench-misc: all @$(MAKE) -C benchmark/misc/function_call/ - @$(NODE) benchmark/common.js misc + @$(NODE) benchmark/run.js misc bench-array: all - @$(NODE) benchmark/common.js arrays + @$(NODE) benchmark/run.js arrays bench-buffer: all - @$(NODE) benchmark/common.js buffers + @$(NODE) benchmark/run.js buffers bench-url: all - @$(NODE) benchmark/common.js url + @$(NODE) benchmark/run.js url bench-events: all - @$(NODE) benchmark/common.js events + @$(NODE) benchmark/run.js events bench-util: all - @$(NODE) benchmark/common.js util + @$(NODE) benchmark/run.js util bench-dgram: all - @$(NODE) benchmark/common.js dgram + @$(NODE) benchmark/run.js dgram bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events bench-dgram bench-util diff --git a/benchmark/README.md b/benchmark/README.md index c3d950f792e31f..18764aae9afcf3 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -24,7 +24,7 @@ There are three ways to run benchmark tests: For example, buffers: ```bash -node benchmark/common.js buffers +node benchmark/run.js buffers ``` The above command will find all scripts under `buffers` directory and require diff --git a/benchmark/common.js b/benchmark/common.js index d49aef106f1c11..3744a4420a09cb 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -15,35 +15,6 @@ if (['default', 'csv', 'silent'].indexOf(outputFormat) == -1) { exports.PORT = process.env.PORT || 12346; -// If this is the main module, then run the benchmarks -if (module === require.main) { - var type = process.argv[2]; - var testFilter = process.argv[3]; - if (!type) { - console.error('usage:\n ./node benchmark/common.js [testFilter]'); - process.exit(1); - } - - var dir = path.join(__dirname, type); - var tests = fs.readdirSync(dir); - - if (testFilter) { - var filteredTests = tests.filter(function(item) { - if (item.lastIndexOf(testFilter) >= 0) { - return item; - } - }); - - if (filteredTests.length === 0) { - console.error('%s is not found in \n %j', testFilter, tests); - return; - } - tests = filteredTests; - } - - runBenchmarks(); -} - function hasWrk() { var result = child_process.spawnSync('wrk', ['-h']); if (result.error && result.error.code === 'ENOENT') { @@ -53,31 +24,6 @@ function hasWrk() { } } -function runBenchmarks() { - var test = tests.shift(); - if (!test) - return; - - if (test.match(/^[\._]/)) - return process.nextTick(runBenchmarks); - - if (outputFormat == 'default') - console.error(type + '/' + test); - - test = path.resolve(dir, test); - - var a = (process.execArgv || []).concat(test); - var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' }); - child.on('close', function(code) { - if (code) { - process.exit(code); - } else { - console.log(''); - runBenchmarks(); - } - }); -} - exports.createBenchmark = function(fn, options) { return new Benchmark(fn, options); }; @@ -262,4 +208,3 @@ exports.v8ForceOptimization = function(method, ...args) { method.apply(null, args); return eval('%GetOptimizationStatus(method)'); }; - diff --git a/benchmark/compare.js b/benchmark/compare.js index 21d4b2b6a4f438..4faa8f8638becd 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -80,7 +80,7 @@ function run() { if (Array.isArray(benchmarks) && benchmarks.length) { child = spawn( node, - ['benchmark/common.js'].concat(benchmarks), + ['benchmark/run.js'].concat(benchmarks), { env: env } ); } else { diff --git a/benchmark/run.js b/benchmark/run.js new file mode 100644 index 00000000000000..ad590ea34a8952 --- /dev/null +++ b/benchmark/run.js @@ -0,0 +1,63 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const child_process = require('child_process'); + +var outputFormat = process.env.OUTPUT_FORMAT || + (+process.env.NODE_BENCH_SILENT ? 'silent' : false) || + 'default'; + +// If this is the main module, then run the benchmarks +if (module === require.main) { + var type = process.argv[2]; + var testFilter = process.argv[3]; + if (!type) { + console.error('usage:\n ./node benchmark/run.js [testFilter]'); + process.exit(1); + } + + var dir = path.join(__dirname, type); + var tests = fs.readdirSync(dir); + + if (testFilter) { + var filteredTests = tests.filter(function(item) { + if (item.lastIndexOf(testFilter) >= 0) { + return item; + } + }); + + if (filteredTests.length === 0) { + console.error('%s is not found in \n %j', testFilter, tests); + return; + } + tests = filteredTests; + } + + runBenchmarks(); +} + +function runBenchmarks() { + var test = tests.shift(); + if (!test) + return; + + if (test.match(/^[\._]/)) + return process.nextTick(runBenchmarks); + + if (outputFormat == 'default') + console.error(type + '/' + test); + + test = path.resolve(dir, test); + + var a = (process.execArgv || []).concat(test); + var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' }); + child.on('close', function(code) { + if (code) { + process.exit(code); + } else { + console.log(''); + runBenchmarks(); + } + }); +}