From 0f9bfaa7c51bb5f4910ddf068ed89b1bdf35e7d5 Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Sat, 30 Jan 2016 14:27:02 +0100 Subject: [PATCH] benchmark: move cli parts of common.js into run.js It wasn't obviouse that common.js was the main cli tool. PR-URL: https://github.com/nodejs/node/pull/7094 Reviewed-By: Trevor Norris Reviewed-By: Jeremiah Senkpiel Reviewed-By: Brian White Reviewed-By: Anna Henningsen --- Makefile | 24 ++++++++--------- benchmark/README.md | 2 +- benchmark/common.js | 55 -------------------------------------- benchmark/compare.js | 2 +- benchmark/run.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 benchmark/run.js diff --git a/Makefile b/Makefile index 1205d1a6a2..c8279682cc 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 c3d950f792..18764aae9a 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 d49aef106f..3744a4420a 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 21d4b2b6a4..4faa8f8638 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 0000000000..ad590ea34a --- /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(); + } + }); +}