From bb43941ca5fdf95414768bbdb72091afa919809a Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 12 Feb 2020 19:33:22 +0100 Subject: [PATCH 1/6] Revert "Revert "benchmark: refactor helper into a class"" This reverts commit 5b0308cd823a511098dadf9ddd5a35e3a9dbb424. --- benchmark/common.js | 429 ++++++++++++++++++++++---------------------- 1 file changed, 215 insertions(+), 214 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index c5791c2bacfd5d..62cd4023c1d860 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -3,222 +3,225 @@ const child_process = require('child_process'); const http_benchmarkers = require('./_http-benchmarkers.js'); -exports.buildType = process.features.debug ? 'Debug' : 'Release'; - -exports.createBenchmark = function(fn, configs, options) { - return new Benchmark(fn, configs, options); -}; - -function Benchmark(fn, configs, options) { - // Use the file name as the name of the benchmark - this.name = require.main.filename.slice(__dirname.length + 1); - // Parse job-specific configuration from the command line arguments - const parsed_args = this._parseArgs(process.argv.slice(2), configs); - this.options = parsed_args.cli; - this.extra_options = parsed_args.extra; - // The configuration list as a queue of jobs - this.queue = this._queue(this.options); - // The configuration of the current job, head of the queue - this.config = this.queue[0]; - // Execution arguments i.e. flags used to run the jobs - this.flags = []; - if (options && options.flags) { - this.flags = this.flags.concat(options.flags); - } - if (process.env.NODE_BENCHMARK_FLAGS) { - const flags = process.env.NODE_BENCHMARK_FLAGS.split(/\s+/); - this.flags = this.flags.concat(flags); - } - // Holds process.hrtime value - this._time = [0, 0]; - // Used to make sure a benchmark only start a timer once - this._started = false; - this._ended = false; - - // this._run will use fork() to create a new process for each configuration - // combination. - if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) { - process.nextTick(() => fn(this.config)); - } else { - process.nextTick(() => this._run()); - } -} - -Benchmark.prototype._parseArgs = function(argv, configs) { - const cliOptions = {}; - const extraOptions = {}; - const validArgRE = /^(.+?)=([\s\S]*)$/; - // Parse configuration arguments - for (const arg of argv) { - const match = arg.match(validArgRE); - if (!match) { - console.error(`bad argument: ${arg}`); - process.exit(1); +class Benchmark { + constructor(fn, configs, options) { + // Use the file name as the name of the benchmark + this.name = require.main.filename.slice(__dirname.length + 1); + // Parse job-specific configuration from the command line arguments + const parsed_args = this._parseArgs(process.argv.slice(2), configs); + this.options = parsed_args.cli; + this.extra_options = parsed_args.extra; + // The configuration list as a queue of jobs + this.queue = this._queue(this.options); + // The configuration of the current job, head of the queue + this.config = this.queue[0]; + // Execution arguments i.e. flags used to run the jobs + this.flags = []; + if (options && options.flags) { + this.flags = this.flags.concat(options.flags); } - const config = match[1]; - - if (configs[config]) { - // Infer the type from the config object and parse accordingly - const isNumber = typeof configs[config][0] === 'number'; - const value = isNumber ? +match[2] : match[2]; - if (!cliOptions[config]) - cliOptions[config] = []; - cliOptions[config].push(value); + if (process.env.NODE_BENCHMARK_FLAGS) { + const flags = process.env.NODE_BENCHMARK_FLAGS.split(/\s+/); + this.flags = this.flags.concat(flags); + } + // Holds process.hrtime value + this._time = [0, 0]; + // Used to make sure a benchmark only start a timer once + this._started = false; + this._ended = false; + + // this._run will use fork() to create a new process for each configuration + // combination. + if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) { + process.nextTick(() => fn(this.config)); } else { - extraOptions[config] = match[2]; + process.nextTick(() => this._run()); } } - return { cli: Object.assign({}, configs, cliOptions), extra: extraOptions }; -}; - -Benchmark.prototype._queue = function(options) { - const queue = []; - const keys = Object.keys(options); - - // Perform a depth-first walk though all options to generate a - // configuration list that contains all combinations. - function recursive(keyIndex, prevConfig) { - const key = keys[keyIndex]; - const values = options[key]; - const type = typeof values[0]; - for (const value of values) { - if (typeof value !== 'number' && typeof value !== 'string') { - throw new TypeError(`configuration "${key}" had type ${typeof value}`); + _parseArgs(argv, configs) { + const cliOptions = {}; + const extraOptions = {}; + const validArgRE = /^(.+?)=([\s\S]*)$/; + // Parse configuration arguments + for (const arg of argv) { + const match = arg.match(validArgRE); + if (!match) { + console.error(`bad argument: ${arg}`); + process.exit(1); } - if (typeof value !== type) { - // This is a requirement for being able to consistently and predictably - // parse CLI provided configuration values. - throw new TypeError(`configuration "${key}" has mixed types`); + const config = match[1]; + + if (configs[config]) { + // Infer the type from the config object and parse accordingly + const isNumber = typeof configs[config][0] === 'number'; + const value = isNumber ? +match[2] : match[2]; + if (!cliOptions[config]) + cliOptions[config] = []; + cliOptions[config].push(value); + } else { + extraOptions[config] = match[2]; } + } + return { cli: Object.assign({}, configs, cliOptions), extra: extraOptions }; + } - const currConfig = Object.assign({ [key]: value }, prevConfig); - - if (keyIndex + 1 < keys.length) { - recursive(keyIndex + 1, currConfig); - } else { - queue.push(currConfig); + _queue(options) { + const queue = []; + const keys = Object.keys(options); + + // Perform a depth-first walk though all options to generate a + // configuration list that contains all combinations. + function recursive(keyIndex, prevConfig) { + const key = keys[keyIndex]; + const values = options[key]; + const type = typeof values[0]; + + for (const value of values) { + if (typeof value !== 'number' && typeof value !== 'string') { + throw new TypeError( + `configuration "${key}" had type ${typeof value}`); + } + if (typeof value !== type) { + // This is a requirement for being able to consistently and + // predictably parse CLI provided configuration values. + throw new TypeError(`configuration "${key}" has mixed types`); + } + + const currConfig = Object.assign({ [key]: value }, prevConfig); + + if (keyIndex + 1 < keys.length) { + recursive(keyIndex + 1, currConfig); + } else { + queue.push(currConfig); + } } } + + if (keys.length > 0) { + recursive(0, {}); + } else { + queue.push({}); + } + + return queue; } - if (keys.length > 0) { - recursive(0, {}); - } else { - queue.push({}); + http(options, cb) { + const self = this; + const http_options = Object.assign({ }, options); + http_options.benchmarker = http_options.benchmarker || + self.config.benchmarker || + self.extra_options.benchmarker || + exports.default_http_benchmarker; + http_benchmarkers.run( + http_options, (error, code, used_benchmarker, result, elapsed) => { + if (cb) { + cb(code); + } + if (error) { + console.error(error); + process.exit(code || 1); + } + self.config.benchmarker = used_benchmarker; + self.report(result, elapsed); + } + ); } - return queue; -}; + _run() { + const self = this; + // If forked, report to the parent. + if (process.send) { + process.send({ + type: 'config', + name: this.name, + queueLength: this.queue.length, + }); + } + + (function recursive(queueIndex) { + const config = self.queue[queueIndex]; -// Benchmark an http server. -exports.default_http_benchmarker = - http_benchmarkers.default_http_benchmarker; -exports.PORT = http_benchmarkers.PORT; - -Benchmark.prototype.http = function(options, cb) { - const self = this; - const http_options = Object.assign({ }, options); - http_options.benchmarker = http_options.benchmarker || - self.config.benchmarker || - self.extra_options.benchmarker || - exports.default_http_benchmarker; - http_benchmarkers.run( - http_options, (error, code, used_benchmarker, result, elapsed) => { - if (cb) { - cb(code); + // Set NODE_RUN_BENCHMARK_FN to indicate that the child shouldn't + // construct a configuration queue, but just execute the benchmark + // function. + const childEnv = Object.assign({}, process.env); + childEnv.NODE_RUN_BENCHMARK_FN = ''; + + // Create configuration arguments + const childArgs = []; + for (const key of Object.keys(config)) { + childArgs.push(`${key}=${config[key]}`); } - if (error) { - console.error(error); - process.exit(code || 1); + for (const key of Object.keys(self.extra_options)) { + childArgs.push(`${key}=${self.extra_options[key]}`); } - self.config.benchmarker = used_benchmarker; - self.report(result, elapsed); - } - ); -}; -Benchmark.prototype._run = function() { - const self = this; - // If forked, report to the parent. - if (process.send) { - process.send({ - type: 'config', - name: this.name, - queueLength: this.queue.length, - }); + const child = child_process.fork(require.main.filename, childArgs, { + env: childEnv, + execArgv: self.flags.concat(process.execArgv), + }); + child.on('message', sendResult); + child.on('close', (code) => { + if (code) { + process.exit(code); + } + + if (queueIndex + 1 < self.queue.length) { + recursive(queueIndex + 1); + } + }); + })(0); } - (function recursive(queueIndex) { - const config = self.queue[queueIndex]; + start() { + if (this._started) { + throw new Error('Called start more than once in a single benchmark'); + } + this._started = true; + this._time = process.hrtime(); + } - // Set NODE_RUN_BENCHMARK_FN to indicate that the child shouldn't construct - // a configuration queue, but just execute the benchmark function. - const childEnv = Object.assign({}, process.env); - childEnv.NODE_RUN_BENCHMARK_FN = ''; + end(operations) { + // Get elapsed time now and do error checking later for accuracy. + const elapsed = process.hrtime(this._time); - // Create configuration arguments - const childArgs = []; - for (const key of Object.keys(config)) { - childArgs.push(`${key}=${config[key]}`); + if (!this._started) { + throw new Error('called end without start'); } - for (const key of Object.keys(self.extra_options)) { - childArgs.push(`${key}=${self.extra_options[key]}`); + if (this._ended) { + throw new Error('called end multiple times'); + } + if (typeof operations !== 'number') { + throw new Error('called end() without specifying operation count'); + } + if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) { + throw new Error('called end() with operation count <= 0'); + } + if (elapsed[0] === 0 && elapsed[1] === 0) { + if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED) + throw new Error('insufficient clock precision for short benchmark'); + // Avoid dividing by zero + elapsed[1] = 1; } - const child = child_process.fork(require.main.filename, childArgs, { - env: childEnv, - execArgv: self.flags.concat(process.execArgv), - }); - child.on('message', sendResult); - child.on('close', (code) => { - if (code) { - process.exit(code); - } - - if (queueIndex + 1 < self.queue.length) { - recursive(queueIndex + 1); - } - }); - })(0); -}; - -Benchmark.prototype.start = function() { - if (this._started) { - throw new Error('Called start more than once in a single benchmark'); + this._ended = true; + const time = elapsed[0] + elapsed[1] / 1e9; + const rate = operations / time; + this.report(rate, elapsed); } - this._started = true; - this._time = process.hrtime(); -}; -Benchmark.prototype.end = function(operations) { - // Get elapsed time now and do error checking later for accuracy. - const elapsed = process.hrtime(this._time); - - if (!this._started) { - throw new Error('called end without start'); - } - if (this._ended) { - throw new Error('called end multiple times'); - } - if (typeof operations !== 'number') { - throw new Error('called end() without specifying operation count'); - } - if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) { - throw new Error('called end() with operation count <= 0'); - } - if (elapsed[0] === 0 && elapsed[1] === 0) { - if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED) - throw new Error('insufficient clock precision for short benchmark'); - // Avoid dividing by zero - elapsed[1] = 1; + report(rate, elapsed) { + sendResult({ + name: this.name, + conf: this.config, + rate: rate, + time: elapsed[0] + elapsed[1] / 1e9, + type: 'report', + }); } - - this._ended = true; - const time = elapsed[0] + elapsed[1] / 1e9; - const rate = operations / time; - this.report(rate, elapsed); -}; +} function formatResult(data) { // Construct configuration string, " A=a, B=b, ..." @@ -242,27 +245,6 @@ function sendResult(data) { console.log(formatResult(data)); } } -exports.sendResult = sendResult; - -Benchmark.prototype.report = function(rate, elapsed) { - sendResult({ - name: this.name, - conf: this.config, - rate: rate, - time: elapsed[0] + elapsed[1] / 1e9, - type: 'report', - }); -}; - -exports.binding = function(bindingName) { - try { - const { internalBinding } = require('internal/test/binding'); - - return internalBinding(bindingName); - } catch { - return process.binding(bindingName); - } -}; const urls = { long: 'http://nodejs.org:89/docs/latest/api/foo/bar/qua/13949281/0f28b/' + @@ -278,7 +260,6 @@ const urls = { percent: 'https://%E4%BD%A0/foo', dot: 'https://example.org/./a/../b/./c', }; -exports.urls = urls; const searchParams = { noencode: 'foo=bar&baz=quux&xyzzy=thud', @@ -293,7 +274,6 @@ const searchParams = { manyblankpairs: '&&&&&&&&&&&&&&&&&&&&&&&&', altspaces: 'foo+bar=baz+quux&xyzzy+thud=quuy+quuz&abc=def+ghi', }; -exports.searchParams = searchParams; function getUrlData(withBase) { const data = require('../test/fixtures/wpt/url/resources/urltestdata.json'); @@ -309,8 +289,6 @@ function getUrlData(withBase) { return result; } -exports.urlDataTypes = Object.keys(urls).concat(['wpt']); - /** * Generate an array of data for URL benchmarks to use. * The size of the resulting data set is the original data size * 2 ** `e`. @@ -354,4 +332,27 @@ function bakeUrlData(type, e = 0, withBase = false, asUrl = false) { } return result; } -exports.bakeUrlData = bakeUrlData; + +module.exports = { + PORT: http_benchmarkers.PORT, + bakeUrlData, + binding(bindingName) { + try { + const { internalBinding } = require('internal/test/binding'); + + return internalBinding(bindingName); + } catch { + return process.binding(bindingName); + } + }, + buildType: process.features.debug ? 'Debug' : 'Release', + createBenchmark(fn, configs, options) { + return new Benchmark(fn, configs, options); + }, + // Benchmark an http server. + default_http_benchmarker: http_benchmarkers.default_http_benchmarker, + sendResult, + searchParams, + urlDataTypes: Object.keys(urls).concat(['wpt']), + urls, +}; From 41834c5c34c1f1f7db2dfd28d65723d43c84bb37 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 12 Feb 2020 19:33:33 +0100 Subject: [PATCH 2/6] Revert "Revert "benchmark: add `test` and `all` options and improve errors"" This reverts commit 4671d551cf9210434bdadf65ee5654606d24da70. --- benchmark/_cli.js | 22 ++- benchmark/_http-benchmarkers.js | 23 ++- benchmark/_test-double-benchmarker.js | 10 +- benchmark/async_hooks/http-server.js | 6 +- benchmark/buffers/buffer-base64-encode.js | 2 + benchmark/buffers/buffer-swap.js | 2 + benchmark/common.js | 177 +++++++++++------- benchmark/compare.js | 2 +- benchmark/crypto/cipher-stream.js | 2 + benchmark/fs/read-stream-throughput.js | 75 ++++---- benchmark/fs/readfile.js | 6 +- benchmark/http/chunked.js | 8 +- benchmark/http/cluster.js | 8 +- benchmark/http/end-vs-write-end.js | 8 +- benchmark/http/headers.js | 6 +- benchmark/http/incoming_headers.js | 16 +- benchmark/http/set-header.js | 10 +- benchmark/http/simple.js | 10 +- benchmark/http2/compat.js | 8 +- benchmark/http2/respond-with-fd.js | 6 +- benchmark/http2/simple.js | 6 +- benchmark/http2/write.js | 6 +- benchmark/misc/trace.js | 6 +- benchmark/net/net-c2s.js | 2 + benchmark/net/net-pipe.js | 2 + benchmark/net/net-s2c.js | 2 + .../net/net-wrap-js-stream-passthrough.js | 1 + benchmark/net/tcp-raw-c2s.js | 5 +- benchmark/net/tcp-raw-pipe.js | 1 + benchmark/net/tcp-raw-s2c.js | 1 + benchmark/run.js | 15 +- benchmark/scatter.js | 2 +- benchmark/tls/secure-pair.js | 2 + benchmark/util/type-check.js | 2 +- benchmark/zlib/pipe.js | 5 + doc/guides/writing-and-running-benchmarks.md | 7 +- test/common/benchmark.js | 9 +- 37 files changed, 292 insertions(+), 189 deletions(-) diff --git a/benchmark/_cli.js b/benchmark/_cli.js index 771cc72bff1964..eb6c4add9799a4 100644 --- a/benchmark/_cli.js +++ b/benchmark/_cli.js @@ -6,15 +6,16 @@ const path = require('path'); // Create an object of all benchmark scripts const benchmarks = {}; fs.readdirSync(__dirname) - .filter((name) => fs.statSync(path.resolve(__dirname, name)).isDirectory()) + .filter((name) => { + return name !== 'fixtures' && + fs.statSync(path.resolve(__dirname, name)).isDirectory(); + }) .forEach((category) => { benchmarks[category] = fs.readdirSync(path.resolve(__dirname, category)) .filter((filename) => filename[0] !== '.' && filename[0] !== '_'); }); function CLI(usage, settings) { - if (!(this instanceof CLI)) return new CLI(usage, settings); - if (process.argv.length < 3) { this.abort(usage); // Abort will exit the process } @@ -22,6 +23,7 @@ function CLI(usage, settings) { this.usage = usage; this.optional = {}; this.items = []; + this.test = false; for (const argName of settings.arrayArgs) { this.optional[argName] = []; @@ -34,7 +36,7 @@ function CLI(usage, settings) { if (arg === '--') { // Only items can follow -- mode = 'item'; - } else if ('both' === mode && arg[0] === '-') { + } else if (mode === 'both' && arg[0] === '-') { // Optional arguments declaration if (arg[1] === '-') { @@ -61,6 +63,8 @@ function CLI(usage, settings) { // The next value can be either an option or an item mode = 'both'; + } else if (arg === 'test') { + this.test = true; } else if (['both', 'item'].includes(mode)) { // item arguments this.items.push(arg); @@ -83,9 +87,15 @@ CLI.prototype.abort = function(msg) { CLI.prototype.benchmarks = function() { const paths = []; + if (this.items.includes('all')) { + this.items = Object.keys(benchmarks); + } + for (const category of this.items) { - if (benchmarks[category] === undefined) - continue; + if (benchmarks[category] === undefined) { + console.error(`The "${category}" category does not exist.`); + process.exit(1); + } for (const scripts of benchmarks[category]) { if (this.shouldSkip(scripts)) continue; diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index 821dab2d55e683..b1b0038435d0c9 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -43,9 +43,8 @@ class AutocannonBenchmarker { } if (!result || !result.requests || !result.requests.average) { return undefined; - } else { - return result.requests.average; } + return result.requests.average; } } @@ -77,9 +76,8 @@ class WrkBenchmarker { const throughput = match && +match[1]; if (!isFinite(throughput)) { return undefined; - } else { - return throughput; } + return throughput; } } @@ -89,7 +87,8 @@ class WrkBenchmarker { */ class TestDoubleBenchmarker { constructor(type) { - // `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'. + // `type` is the type of benchmarker. Possible values are 'http' and + // 'http2'. this.name = `test-double-${type}`; this.executable = path.resolve(__dirname, '_test-double-benchmarker.js'); this.present = fs.existsSync(this.executable); @@ -97,10 +96,11 @@ class TestDoubleBenchmarker { } create(options) { - const env = Object.assign({ + const env = { duration: options.duration, test_url: `http://127.0.0.1:${options.port}${options.path}`, - }, process.env); + ...process.env + }; const child = child_process.fork(this.executable, [this.type], @@ -189,13 +189,14 @@ http_benchmarkers.forEach((benchmarker) => { }); exports.run = function(options, callback) { - options = Object.assign({ + options = { port: exports.PORT, path: '/', connections: 100, duration: 5, benchmarker: exports.default_http_benchmarker, - }, options); + ...options + }; if (!options.benchmarker) { callback(new Error('Could not locate required http benchmarker. See ' + `${requirementsURL} for further instructions.`)); @@ -212,6 +213,7 @@ exports.run = function(options, callback) { 'is not installed')); return; } + process.env.duration = process.env.duration || options.duration || 5; const benchmarker_start = process.hrtime(); @@ -220,7 +222,8 @@ exports.run = function(options, callback) { child.stderr.pipe(process.stderr); let stdout = ''; - child.stdout.on('data', (chunk) => stdout += chunk.toString()); + child.stdout.setEncoding('utf8'); + child.stdout.on('data', (chunk) => stdout += chunk); child.once('close', (code) => { const elapsed = process.hrtime(benchmarker_start); diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index b9379b907ffa07..60264dfd46a606 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -7,7 +7,7 @@ if (!['http', 'http2'].includes(myModule)) { const http = require(myModule); -const duration = process.env.duration || 0; +const duration = +process.env.duration; const url = process.env.test_url; const start = process.hrtime(); @@ -18,13 +18,15 @@ function request(res, client) { res.on('error', () => {}); res.on('end', () => { throughput++; - const diff = process.hrtime(start); - if (duration > 0 && diff[0] < duration) { + const [sec, nanosec] = process.hrtime(start); + const ms = sec * 1000 + nanosec / 1e6; + if (ms < duration * 1000) { run(); } else { console.log(JSON.stringify({ throughput })); if (client) { client.destroy(); + process.exit(0); } } }); @@ -33,7 +35,7 @@ function request(res, client) { function run() { if (http.get) { // HTTP http.get(url, request); - } else { // HTTP/2 + } else { // HTTP/2 const client = http.connect(url); client.on('error', (e) => { throw e; }); request(client.request(), client); diff --git a/benchmark/async_hooks/http-server.js b/benchmark/async_hooks/http-server.js index 9e1c1214240eaa..c8e44849b7466f 100644 --- a/benchmark/async_hooks/http-server.js +++ b/benchmark/async_hooks/http-server.js @@ -3,10 +3,11 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'], - connections: [50, 500] + connections: [50, 500], + duration: 5 }); -function main({ asyncHooks, connections }) { +function main({ asyncHooks, connections, duration }) { if (asyncHooks !== 'none') { let hooks = { init() {}, @@ -33,6 +34,7 @@ function main({ asyncHooks, connections }) { bench.http({ connections, path, + duration }, () => { server.close(); }); diff --git a/benchmark/buffers/buffer-base64-encode.js b/benchmark/buffers/buffer-base64-encode.js index d8b601bbd181f4..9837828a353c2d 100644 --- a/benchmark/buffers/buffer-base64-encode.js +++ b/benchmark/buffers/buffer-base64-encode.js @@ -25,6 +25,8 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { len: [64 * 1024 * 1024], n: [32] +}, { + test: { len: 256 } }); function main({ n, len }) { diff --git a/benchmark/buffers/buffer-swap.js b/benchmark/buffers/buffer-swap.js index a33bac4ae3ed78..5c31d86f7e2ab4 100644 --- a/benchmark/buffers/buffer-swap.js +++ b/benchmark/buffers/buffer-swap.js @@ -7,6 +7,8 @@ const bench = common.createBenchmark(main, { method: ['swap16', 'swap32', 'swap64'/* , 'htons', 'htonl', 'htonll' */], len: [64, 256, 768, 1024, 2056, 8192], n: [1e6] +}, { + test: { len: 16 } }); // The htons and htonl methods below are used to benchmark the diff --git a/benchmark/common.js b/benchmark/common.js index 62cd4023c1d860..d2103704ab2838 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -4,43 +4,83 @@ const child_process = require('child_process'); const http_benchmarkers = require('./_http-benchmarkers.js'); class Benchmark { - constructor(fn, configs, options) { - // Use the file name as the name of the benchmark - this.name = require.main.filename.slice(__dirname.length + 1); + // Used to make sure a benchmark only start a timer once + #started = false; + + // Indicate that the benchmark ended + #ended = false; + + // Holds process.hrtime value + #time = [0, 0]; + + // Use the file name as the name of the benchmark + name = require.main.filename.slice(__dirname.length + 1); + + // Execution arguments i.e. flags used to run the jobs + flags = process.env.NODE_BENCHMARK_FLAGS ? + process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) : + []; + + constructor(fn, configs, options = {}) { // Parse job-specific configuration from the command line arguments - const parsed_args = this._parseArgs(process.argv.slice(2), configs); + const argv = process.argv.slice(2); + const parsed_args = this._parseArgs(argv, configs, options); this.options = parsed_args.cli; this.extra_options = parsed_args.extra; + if (options.flags) { + this.flags = this.flags.concat(options.flags); + } + // The configuration list as a queue of jobs this.queue = this._queue(this.options); + // The configuration of the current job, head of the queue this.config = this.queue[0]; - // Execution arguments i.e. flags used to run the jobs - this.flags = []; - if (options && options.flags) { - this.flags = this.flags.concat(options.flags); - } - if (process.env.NODE_BENCHMARK_FLAGS) { - const flags = process.env.NODE_BENCHMARK_FLAGS.split(/\s+/); - this.flags = this.flags.concat(flags); - } - // Holds process.hrtime value - this._time = [0, 0]; - // Used to make sure a benchmark only start a timer once - this._started = false; - this._ended = false; - - // this._run will use fork() to create a new process for each configuration - // combination. - if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) { - process.nextTick(() => fn(this.config)); - } else { - process.nextTick(() => this._run()); - } + + process.nextTick(() => { + if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) { + fn(this.config); + } else { + // _run will use fork() to create a new process for each configuration + // combination. + this._run(); + } + }); } - _parseArgs(argv, configs) { + _parseArgs(argv, configs, options) { const cliOptions = {}; + + // Check for the test mode first. + const testIndex = argv.indexOf('--test'); + if (testIndex !== -1) { + for (const [key, rawValue] of Object.entries(configs)) { + let value = Array.isArray(rawValue) ? rawValue[0] : rawValue; + // Set numbers to one by default to reduce the runtime. + if (typeof value === 'number') { + if (key === 'dur' || key === 'duration') { + value = 0.05; + } else if (value > 1) { + value = 1; + } + } + cliOptions[key] = [value]; + } + // Override specific test options. + if (options.test) { + for (const [key, value] of Object.entries(options.test)) { + cliOptions[key] = Array.isArray(value) ? value : [value]; + } + } + argv.splice(testIndex, 1); + } else { + // Accept single values instead of arrays. + for (const [key, value] of Object.entries(configs)) { + if (!Array.isArray(value)) + configs[key] = [value]; + } + } + const extraOptions = {}; const validArgRE = /^(.+?)=([\s\S]*)$/; // Parse configuration arguments @@ -50,45 +90,43 @@ class Benchmark { console.error(`bad argument: ${arg}`); process.exit(1); } - const config = match[1]; - - if (configs[config]) { - // Infer the type from the config object and parse accordingly - const isNumber = typeof configs[config][0] === 'number'; - const value = isNumber ? +match[2] : match[2]; - if (!cliOptions[config]) - cliOptions[config] = []; - cliOptions[config].push(value); + const [, key, value] = match; + if (Object.prototype.hasOwnProperty.call(configs, key)) { + if (!cliOptions[key]) + cliOptions[key] = []; + cliOptions[key].push( + // Infer the type from the config object and parse accordingly + typeof configs[key][0] === 'number' ? +value : value + ); } else { - extraOptions[config] = match[2]; + extraOptions[key] = value; } } - return { cli: Object.assign({}, configs, cliOptions), extra: extraOptions }; + return { cli: { ...configs, ...cliOptions }, extra: extraOptions }; } _queue(options) { const queue = []; const keys = Object.keys(options); - // Perform a depth-first walk though all options to generate a + // Perform a depth-first walk through all options to generate a // configuration list that contains all combinations. function recursive(keyIndex, prevConfig) { const key = keys[keyIndex]; const values = options[key]; - const type = typeof values[0]; for (const value of values) { if (typeof value !== 'number' && typeof value !== 'string') { throw new TypeError( `configuration "${key}" had type ${typeof value}`); } - if (typeof value !== type) { + if (typeof value !== typeof values[0]) { // This is a requirement for being able to consistently and // predictably parse CLI provided configuration values. throw new TypeError(`configuration "${key}" has mixed types`); } - const currConfig = Object.assign({ [key]: value }, prevConfig); + const currConfig = { [key]: value, ...prevConfig }; if (keyIndex + 1 < keys.length) { recursive(keyIndex + 1, currConfig); @@ -108,12 +146,11 @@ class Benchmark { } http(options, cb) { - const self = this; - const http_options = Object.assign({ }, options); + const http_options = { ...options }; http_options.benchmarker = http_options.benchmarker || - self.config.benchmarker || - self.extra_options.benchmarker || - exports.default_http_benchmarker; + this.config.benchmarker || + this.extra_options.benchmarker || + http_benchmarkers.default_http_benchmarker; http_benchmarkers.run( http_options, (error, code, used_benchmarker, result, elapsed) => { if (cb) { @@ -123,14 +160,13 @@ class Benchmark { console.error(error); process.exit(code || 1); } - self.config.benchmarker = used_benchmarker; - self.report(result, elapsed); + this.config.benchmarker = used_benchmarker; + this.report(result, elapsed); } ); } _run() { - const self = this; // If forked, report to the parent. if (process.send) { process.send({ @@ -140,27 +176,27 @@ class Benchmark { }); } - (function recursive(queueIndex) { - const config = self.queue[queueIndex]; + const recursive = (queueIndex) => { + const config = this.queue[queueIndex]; // Set NODE_RUN_BENCHMARK_FN to indicate that the child shouldn't // construct a configuration queue, but just execute the benchmark // function. - const childEnv = Object.assign({}, process.env); + const childEnv = { ...process.env }; childEnv.NODE_RUN_BENCHMARK_FN = ''; // Create configuration arguments const childArgs = []; - for (const key of Object.keys(config)) { - childArgs.push(`${key}=${config[key]}`); + for (const [key, value] of Object.entries(config)) { + childArgs.push(`${key}=${value}`); } - for (const key of Object.keys(self.extra_options)) { - childArgs.push(`${key}=${self.extra_options[key]}`); + for (const [key, value] of Object.entries(this.extra_options)) { + childArgs.push(`${key}=${value}`); } const child = child_process.fork(require.main.filename, childArgs, { env: childEnv, - execArgv: self.flags.concat(process.execArgv), + execArgv: this.flags.concat(process.execArgv), }); child.on('message', sendResult); child.on('close', (code) => { @@ -168,29 +204,31 @@ class Benchmark { process.exit(code); } - if (queueIndex + 1 < self.queue.length) { + if (queueIndex + 1 < this.queue.length) { recursive(queueIndex + 1); } }); - })(0); + }; + + recursive(0); } start() { - if (this._started) { + if (this.#started) { throw new Error('Called start more than once in a single benchmark'); } - this._started = true; - this._time = process.hrtime(); + this.#started = true; + this.#time = process.hrtime(); } end(operations) { // Get elapsed time now and do error checking later for accuracy. - const elapsed = process.hrtime(this._time); + const elapsed = process.hrtime(this.#time); - if (!this._started) { + if (!this.#started) { throw new Error('called end without start'); } - if (this._ended) { + if (this.#ended) { throw new Error('called end multiple times'); } if (typeof operations !== 'number') { @@ -206,7 +244,7 @@ class Benchmark { elapsed[1] = 1; } - this._ended = true; + this.#ended = true; const time = elapsed[0] + elapsed[1] / 1e9; const rate = operations / time; this.report(rate, elapsed); @@ -216,7 +254,7 @@ class Benchmark { sendResult({ name: this.name, conf: this.config, - rate: rate, + rate, time: elapsed[0] + elapsed[1] / 1e9, type: 'report', }); @@ -334,6 +372,7 @@ function bakeUrlData(type, e = 0, withBase = false, asUrl = false) { } module.exports = { + Benchmark, PORT: http_benchmarkers.PORT, bakeUrlData, binding(bindingName) { @@ -349,8 +388,6 @@ module.exports = { createBenchmark(fn, configs, options) { return new Benchmark(fn, configs, options); }, - // Benchmark an http server. - default_http_benchmarker: http_benchmarkers.default_http_benchmarker, sendResult, searchParams, urlDataTypes: Object.keys(urls).concat(['wpt']), diff --git a/benchmark/compare.js b/benchmark/compare.js index 53f82bb4b9f1b9..5c9cd03be3fdee 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -9,7 +9,7 @@ const BenchmarkProgress = require('./_benchmark_progress.js'); // // Parse arguments // -const cli = CLI(`usage: ./node compare.js [options] [--] ... +const cli = new CLI(`usage: ./node compare.js [options] [--] ... Run each benchmark in the directory many times using two different node versions. More than one directory can be specified. The output is formatted as csv, which can be processed using for diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index 4bb1695e2d20cc..9f4a1bb4fa3d40 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -7,6 +7,8 @@ const bench = common.createBenchmark(main, { type: ['asc', 'utf', 'buf'], len: [2, 1024, 102400, 1024 * 1024], api: ['legacy', 'stream'] +}, { + flags: ['--no-warnings'] }); function main({ api, cipher, type, len, writes }) { diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index 34c25760ea9c38..5984317ff91743 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -11,19 +11,18 @@ tmpdir.refresh(); const filename = path.resolve(tmpdir.path, `.removeme-benchmark-garbage-${process.pid}`); -let encodingType, encoding, size, filesize; - const bench = common.createBenchmark(main, { encodingType: ['buf', 'asc', 'utf'], - filesize: [1000 * 1024 * 1024], - size: [1024, 4096, 65535, 1024 * 1024] + filesize: [1000 * 1024], + highWaterMark: [1024, 4096, 65535, 1024 * 1024], + n: 1024 }); function main(conf) { - encodingType = conf.encodingType; - size = conf.size; - filesize = conf.filesize; + const { encodingType, highWaterMark, filesize } = conf; + let { n } = conf; + let encoding = ''; switch (encodingType) { case 'buf': encoding = null; @@ -38,34 +37,8 @@ function main(conf) { throw new Error(`invalid encodingType: ${encodingType}`); } - makeFile(); -} - -function runTest() { - assert(fs.statSync(filename).size === filesize); - const rs = fs.createReadStream(filename, { - highWaterMark: size, - encoding: encoding - }); - - rs.on('open', () => { - bench.start(); - }); - - let bytes = 0; - rs.on('data', (chunk) => { - bytes += chunk.length; - }); - - rs.on('end', () => { - try { fs.unlinkSync(filename); } catch {} - // MB/sec - bench.end(bytes / (1024 * 1024)); - }); -} - -function makeFile() { - const buf = Buffer.allocUnsafe(filesize / 1024); + // Make file + const buf = Buffer.allocUnsafe(filesize); if (encoding === 'utf8') { // ü for (let i = 0; i < buf.length; i++) { @@ -78,16 +51,38 @@ function makeFile() { } try { fs.unlinkSync(filename); } catch {} - let w = 1024; const ws = fs.createWriteStream(filename); - ws.on('close', runTest); + ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n)); ws.on('drain', write); write(); function write() { do { - w--; - } while (false !== ws.write(buf) && w > 0); - if (w === 0) + n--; + } while (false !== ws.write(buf) && n > 0); + if (n === 0) ws.end(); } } + +function runTest(filesize, highWaterMark, encoding, n) { + assert(fs.statSync(filename).size === filesize * n); + const rs = fs.createReadStream(filename, { + highWaterMark, + encoding + }); + + rs.on('open', () => { + bench.start(); + }); + + let bytes = 0; + rs.on('data', (chunk) => { + bytes += chunk.length; + }); + + rs.on('end', () => { + try { fs.unlinkSync(filename); } catch {} + // MB/sec + bench.end(bytes / (1024 * 1024)); + }); +} diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index 361ffbff597d6e..3f996e02ede876 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -14,12 +14,12 @@ const filename = path.resolve(tmpdir.path, `.removeme-benchmark-garbage-${process.pid}`); const bench = common.createBenchmark(main, { - dur: [5], + duration: [5], len: [1024, 16 * 1024 * 1024], concurrent: [1, 10] }); -function main({ len, dur, concurrent }) { +function main({ len, duration, concurrent }) { try { fs.unlinkSync(filename); } catch {} let data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); @@ -33,7 +33,7 @@ function main({ len, dur, concurrent }) { bench.end(reads); try { fs.unlinkSync(filename); } catch {} process.exit(0); - }, dur * 1000); + }, duration * 1000); function read() { fs.readFile(filename, afterRead); diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js index 52b4605715c322..9ae7bb7495f29a 100644 --- a/benchmark/http/chunked.js +++ b/benchmark/http/chunked.js @@ -13,10 +13,11 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { n: [1, 4, 8, 16], len: [1, 64, 256], - c: [100] + c: [100], + duration: 5 }); -function main({ len, n, c }) { +function main({ len, n, c, duration }) { const http = require('http'); const chunk = Buffer.alloc(len, '8'); @@ -33,7 +34,8 @@ function main({ len, n, c }) { server.listen(common.PORT, () => { bench.http({ - connections: c + connections: c, + duration }, () => { server.close(); }); diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 3bcd061a0894c5..0d97b516ec506b 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -9,14 +9,15 @@ if (cluster.isMaster) { // Unicode confuses ab on os x. type: ['bytes', 'buffer'], len: [4, 1024, 102400], - c: [50, 500] + c: [50, 500], + duration: 5, }); } else { const port = parseInt(process.env.PORT || PORT); require('../fixtures/simple-http-server.js').listen(port); } -function main({ type, len, c }) { +function main({ type, len, c, duration }) { process.env.PORT = PORT; let workers = 0; const w1 = cluster.fork(); @@ -32,7 +33,8 @@ function main({ type, len, c }) { bench.http({ path: path, - connections: c + connections: c, + duration }, () => { w1.destroy(); w2.destroy(); diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js index 38e9b89a97a6b4..60174ef3adf4f2 100644 --- a/benchmark/http/end-vs-write-end.js +++ b/benchmark/http/end-vs-write-end.js @@ -14,10 +14,11 @@ const bench = common.createBenchmark(main, { type: ['asc', 'utf', 'buf'], len: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], c: [100], - method: ['write', 'end'] + method: ['write', 'end'], + duration: 5 }); -function main({ len, type, method, c }) { +function main({ len, type, method, c, duration }) { const http = require('http'); let chunk; switch (type) { @@ -49,7 +50,8 @@ function main({ len, type, method, c }) { server.listen(common.PORT, () => { bench.http({ - connections: c + connections: c, + duration }, () => { server.close(); }); diff --git a/benchmark/http/headers.js b/benchmark/http/headers.js index f8014a6a085d19..b83ac17e742a2e 100644 --- a/benchmark/http/headers.js +++ b/benchmark/http/headers.js @@ -6,9 +6,10 @@ const http = require('http'); const bench = common.createBenchmark(main, { n: [10, 1000], len: [1, 100], + duration: 5 }); -function main({ len, n }) { +function main({ len, n, duration }) { const headers = { 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked', @@ -29,7 +30,8 @@ function main({ len, n }) { server.listen(common.PORT, () => { bench.http({ path: '/', - connections: 10 + connections: 10, + duration }, () => { server.close(); }); diff --git a/benchmark/http/incoming_headers.js b/benchmark/http/incoming_headers.js index 810c92687bd981..983bd5632fcb7d 100644 --- a/benchmark/http/incoming_headers.js +++ b/benchmark/http/incoming_headers.js @@ -3,12 +3,13 @@ const common = require('../common.js'); const http = require('http'); const bench = common.createBenchmark(main, { - c: [50], // Concurrent connections - n: [20], // Number of header lines to append after the common headers - w: [0, 6], // Amount of trailing whitespace + connections: [50], // Concurrent connections + headers: [20], // Number of header lines to append after the common headers + w: [0, 6], // Amount of trailing whitespace + duration: 5 }); -function main({ c, n, w }) { +function main({ connections, headers, w, duration }) { const server = http.createServer((req, res) => { res.end(); }); @@ -21,7 +22,7 @@ function main({ c, n, w }) { 'Date': new Date().toString(), 'Cache-Control': 'no-cache' }; - for (let i = 0; i < n; i++) { + for (let i = 0; i < headers; i++) { // Note: // - autocannon does not send header values with OWS // - wrk can only send trailing OWS. This is a side-effect of wrk @@ -31,8 +32,9 @@ function main({ c, n, w }) { } bench.http({ path: '/', - connections: c, - headers + connections, + headers, + duration }, () => { server.close(); }); diff --git a/benchmark/http/set-header.js b/benchmark/http/set-header.js index 1909c0991dfc71..48e0163a6ced10 100644 --- a/benchmark/http/set-header.js +++ b/benchmark/http/set-header.js @@ -3,7 +3,8 @@ const common = require('../common.js'); const PORT = common.PORT; const bench = common.createBenchmark(main, { - res: ['normal', 'setHeader', 'setHeaderWH'] + res: ['normal', 'setHeader', 'setHeaderWH'], + duration: 5 }); const type = 'bytes'; @@ -15,16 +16,17 @@ const c = 50; // normal: writeHead(status, {...}) // setHeader: statusCode = status, setHeader(...) x2 // setHeaderWH: setHeader(...), writeHead(status, ...) -function main({ res }) { +function main({ res, duration }) { process.env.PORT = PORT; const server = require('../fixtures/simple-http-server.js') .listen(PORT) .on('listening', () => { - const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`; + const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`; bench.http({ path: path, - connections: c + connections: c, + duration }, () => { server.close(); }); diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 95409faa9a869c..095b15ca4465fb 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -7,18 +7,20 @@ const bench = common.createBenchmark(main, { len: [4, 1024, 102400], chunks: [1, 4], c: [50, 500], - chunkedEnc: [1, 0] + chunkedEnc: [1, 0], + duration: 5 }); -function main({ type, len, chunks, c, chunkedEnc, res }) { +function main({ type, len, chunks, c, chunkedEnc, duration }) { const server = require('../fixtures/simple-http-server.js') .listen(common.PORT) .on('listening', () => { const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`; bench.http({ - path: path, - connections: c + path, + connections: c, + duration }, () => { server.close(); }); diff --git a/benchmark/http2/compat.js b/benchmark/http2/compat.js index 5d06ccf3178257..2c7e732b07f0a5 100644 --- a/benchmark/http2/compat.js +++ b/benchmark/http2/compat.js @@ -9,10 +9,11 @@ const bench = common.createBenchmark(main, { requests: [100, 1000, 5000], streams: [1, 10, 20, 40, 100, 200], clients: [2], - benchmarker: ['h2load'] + benchmarker: ['test-double-http2'], + duration: 5 }, { flags: ['--no-warnings'] }); -function main({ requests, streams, clients }) { +function main({ requests, streams, clients, duration }) { const http2 = require('http2'); const server = http2.createServer(); server.on('request', (req, res) => { @@ -29,7 +30,8 @@ function main({ requests, streams, clients }) { requests, maxConcurrentStreams: streams, clients, - threads: clients + threads: clients, + duration }, () => { server.close(); }); }); } diff --git a/benchmark/http2/respond-with-fd.js b/benchmark/http2/respond-with-fd.js index 35856490f7e4a2..5bf5988d16a64c 100644 --- a/benchmark/http2/respond-with-fd.js +++ b/benchmark/http2/respond-with-fd.js @@ -10,10 +10,11 @@ const bench = common.createBenchmark(main, { requests: [100, 1000, 5000], streams: [1, 10, 20, 40, 100, 200], clients: [2], - benchmarker: ['h2load'] + benchmarker: ['test-double-http2'], + duration: 5 }, { flags: ['--no-warnings'] }); -function main({ requests, streams, clients }) { +function main({ requests, streams, clients, duration }) { fs.open(file, 'r', (err, fd) => { if (err) throw err; @@ -30,6 +31,7 @@ function main({ requests, streams, clients }) { requests, maxConcurrentStreams: streams, clients, + duration, threads: clients }, () => server.close()); }); diff --git a/benchmark/http2/simple.js b/benchmark/http2/simple.js index aab7c6b609b715..929c4c655e1295 100644 --- a/benchmark/http2/simple.js +++ b/benchmark/http2/simple.js @@ -9,10 +9,11 @@ const bench = common.createBenchmark(main, { requests: [100, 1000, 5000], streams: [1, 10, 20, 40, 100, 200], clients: [2], - benchmarker: ['h2load'] + benchmarker: ['test-double-http2'], + duration: 5 }, { flags: ['--no-warnings'] }); -function main({ requests, streams, clients }) { +function main({ requests, streams, clients, duration }) { const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream) => { @@ -27,6 +28,7 @@ function main({ requests, streams, clients }) { requests, maxConcurrentStreams: streams, clients, + duration, threads: clients }, () => { server.close(); }); }); diff --git a/benchmark/http2/write.js b/benchmark/http2/write.js index fc3203c6e55451..7ea8b2c02da650 100644 --- a/benchmark/http2/write.js +++ b/benchmark/http2/write.js @@ -6,10 +6,11 @@ const bench = common.createBenchmark(main, { streams: [100, 200, 1000], length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], size: [100000], - benchmarker: ['h2load'] + benchmarker: ['test-double-http2'], + duration: 5 }, { flags: ['--no-warnings'] }); -function main({ streams, length, size }) { +function main({ streams, length, size, duration }) { const http2 = require('http2'); const server = http2.createServer(); server.on('stream', (stream) => { @@ -29,6 +30,7 @@ function main({ streams, length, size }) { bench.http({ path: '/', requests: 10000, + duration, maxConcurrentStreams: streams, }, () => { server.close(); }); }); diff --git a/benchmark/misc/trace.js b/benchmark/misc/trace.js index bdbf547007e72e..f06e8597cc30e9 100644 --- a/benchmark/misc/trace.js +++ b/benchmark/misc/trace.js @@ -6,7 +6,11 @@ const bench = common.createBenchmark(main, { n: [100000], method: ['trace', 'isTraceCategoryEnabled'] }, { - flags: ['--expose-internals', '--trace-event-categories', 'foo'] + flags: [ + '--expose-internals', + '--no-warnings', + '--trace-event-categories', 'foo', + ] }); const { diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js index cacd6815630b2e..424c8f6dd072b3 100644 --- a/benchmark/net/net-c2s.js +++ b/benchmark/net/net-c2s.js @@ -9,6 +9,8 @@ const bench = common.createBenchmark(main, { len: [64, 102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5], +}, { + test: { len: 1024 } }); let chunk; diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js index d86ff73041d845..32e1085299a2ce 100644 --- a/benchmark/net/net-pipe.js +++ b/benchmark/net/net-pipe.js @@ -9,6 +9,8 @@ const bench = common.createBenchmark(main, { len: [2, 64, 102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5], +}, { + test: { len: 1024 } }); let chunk; diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index 789eadf0a18dba..835cc67567bcf2 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -10,6 +10,8 @@ const bench = common.createBenchmark(main, { recvbuflen: [0, 64 * 1024, 1024 * 1024], recvbufgenfn: ['true', 'false'], dur: [5] +}, { + test: { sendchunklen: 256 } }); let chunk; diff --git a/benchmark/net/net-wrap-js-stream-passthrough.js b/benchmark/net/net-wrap-js-stream-passthrough.js index 0d7be36c6aa545..3824cfb9c0e03c 100644 --- a/benchmark/net/net-wrap-js-stream-passthrough.js +++ b/benchmark/net/net-wrap-js-stream-passthrough.js @@ -9,6 +9,7 @@ const bench = common.createBenchmark(main, { type: ['utf', 'asc', 'buf'], dur: [5], }, { + test: { len: 64 }, flags: ['--expose-internals'] }); diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index b8af124a7f40fc..9547c01f38bc32 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -12,7 +12,10 @@ const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] -}, { flags: [ '--expose-internals', '--no-warnings' ] }); +}, { + test: { len: 1024 }, + flags: [ '--expose-internals', '--no-warnings' ] +}); function main({ dur, len, type }) { const { diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index 249b61046a84cf..e422ff749fd545 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -13,6 +13,7 @@ const bench = common.createBenchmark(main, { type: ['utf', 'asc', 'buf'], dur: [5] }, { + test: { len: 1024 }, flags: [ '--expose-internals', '--no-warnings' ] }); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 393cf060489cb8..be7279ca0c315c 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -13,6 +13,7 @@ const bench = common.createBenchmark(main, { type: ['utf', 'asc', 'buf'], dur: [5] }, { + test: { len: 1024 }, flags: [ '--expose-internals', '--no-warnings' ] }); diff --git a/benchmark/run.js b/benchmark/run.js index 8e81a2c5e16ab7..eae990ce5b2566 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -4,7 +4,7 @@ const path = require('path'); const fork = require('child_process').fork; const CLI = require('./_cli.js'); -const cli = CLI(`usage: ./node run.js [options] [--] ... +const cli = new CLI(`usage: ./node run.js [options] [--] ... Run each benchmark in the directory a single time, more than one directory can be specified. @@ -14,6 +14,9 @@ const cli = CLI(`usage: ./node run.js [options] [--] ... repeated) --set variable=value set benchmark variable (can be repeated) --format [simple|csv] optional value that specifies the output format + test only run a single configuration from the options + matrix + all each benchmark category is run one after the other `, { arrayArgs: ['set', 'filter', 'exclude'] }); const benchmarks = cli.benchmarks(); @@ -37,7 +40,11 @@ if (format === 'csv') { (function recursive(i) { const filename = benchmarks[i]; - const child = fork(path.resolve(__dirname, filename), cli.optional.set); + const child = fork( + path.resolve(__dirname, filename), + cli.test ? ['--test'] : [], + cli.optional.set + ); if (format !== 'csv') { console.log(); @@ -51,10 +58,10 @@ if (format === 'csv') { // Construct configuration string, " A=a, B=b, ..." let conf = ''; for (const key of Object.keys(data.conf)) { + if (conf !== '') + conf += ' '; conf += ` ${key}=${JSON.stringify(data.conf[key])}`; } - // Delete first space of the configuration - conf = conf.slice(1); if (format === 'csv') { // Escape quotes (") for correct csv formatting conf = conf.replace(/"/g, '""'); diff --git a/benchmark/scatter.js b/benchmark/scatter.js index 10649e6bb51e97..ecbf8e0041c837 100644 --- a/benchmark/scatter.js +++ b/benchmark/scatter.js @@ -7,7 +7,7 @@ const CLI = require('./_cli.js'); // // Parse arguments // -const cli = CLI(`usage: ./node scatter.js [options] [--] +const cli = new CLI(`usage: ./node scatter.js [options] [--] Run the benchmark script many times and output the rate (ops/s) together with the benchmark variables as a csv. diff --git a/benchmark/tls/secure-pair.js b/benchmark/tls/secure-pair.js index bb7933d837f999..76658fc3c42ad7 100644 --- a/benchmark/tls/secure-pair.js +++ b/benchmark/tls/secure-pair.js @@ -4,6 +4,8 @@ const bench = common.createBenchmark(main, { dur: [5], securing: ['SecurePair', 'TLSSocket', 'clear'], size: [100, 1024, 1024 * 1024] +}, { + flags: ['--no-warnings'] }); const fixtures = require('../../test/common/fixtures'); diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js index 5b992e729e63ae..8d57bc000afcd1 100644 --- a/benchmark/util/type-check.js +++ b/benchmark/util/type-check.js @@ -31,7 +31,7 @@ const bench = common.createBenchmark(main, { argument: ['true', 'false-primitive', 'false-object'], n: [1e5] }, { - flags: ['--expose-internals'] + flags: ['--expose-internals', '--no-warnings'] }); function main({ type, argument, version, n }) { diff --git a/benchmark/zlib/pipe.js b/benchmark/zlib/pipe.js index 6a1c427bc8380b..76b0ddc6c65a25 100644 --- a/benchmark/zlib/pipe.js +++ b/benchmark/zlib/pipe.js @@ -8,6 +8,11 @@ const bench = common.createBenchmark(main, { duration: [5], type: ['string', 'buffer'], algorithm: ['gzip', 'brotli'] +}, { + test: { + inputLen: 1024, + duration: 0.2 + } }); function main({ inputLen, duration, type, algorithm }) { diff --git a/doc/guides/writing-and-running-benchmarks.md b/doc/guides/writing-and-running-benchmarks.md index 1db72d22de5324..0075023ce80fa8 100644 --- a/doc/guides/writing-and-running-benchmarks.md +++ b/doc/guides/writing-and-running-benchmarks.md @@ -519,7 +519,8 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { kb: [64, 128, 256, 1024], - connections: [100, 500] + connections: [100, 500], + duration: 5 }); function main(conf) { @@ -546,8 +547,8 @@ Supported options keys are: * `path` - defaults to `/` * `connections` - number of concurrent connections to use, defaults to 100 * `duration` - duration of the benchmark in seconds, defaults to 10 -* `benchmarker` - benchmarker to use, defaults to -`common.default_http_benchmarker` +* `benchmarker` - benchmarker to use, defaults to the first available http + benchmarker [autocannon]: https://github.com/mcollina/autocannon [wrk]: https://github.com/wg/wrk diff --git a/test/common/benchmark.js b/test/common/benchmark.js index f630bb9d0e6fd8..56351c92505efa 100644 --- a/test/common/benchmark.js +++ b/test/common/benchmark.js @@ -8,13 +8,8 @@ const path = require('path'); const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); -function runBenchmark(name, args, env) { - const argv = []; - - for (let i = 0; i < args.length; i++) { - argv.push('--set'); - argv.push(args[i]); - } +function runBenchmark(name, env) { + const argv = ['test']; argv.push(name); From ac2514b345b36668c61896654b6e9d55edbcfbe2 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 12 Feb 2020 19:34:00 +0100 Subject: [PATCH 3/6] Revert "Revert "test: refactor all benchmark tests to use the new test option"" This reverts commit aa0a01bd36101ab087f81a7e8caeca9d3ccc9beb. --- test/benchmark/test-benchmark-assert.js | 13 +-------- test/benchmark/test-benchmark-async-hooks.js | 11 +------- test/benchmark/test-benchmark-buffer.js | 28 +------------------ .../benchmark/test-benchmark-child-process.js | 10 +------ test/benchmark/test-benchmark-cluster.js | 7 +---- test/benchmark/test-benchmark-crypto.js | 16 +---------- test/benchmark/test-benchmark-dgram.js | 13 ++------- test/benchmark/test-benchmark-dns.js | 4 +-- test/benchmark/test-benchmark-domain.js | 2 +- test/benchmark/test-benchmark-es.js | 13 +-------- test/benchmark/test-benchmark-events.js | 4 +-- test/benchmark/test-benchmark-fs.js | 17 +---------- test/benchmark/test-benchmark-http.js | 25 +---------------- test/benchmark/test-benchmark-http2.js | 15 +--------- test/benchmark/test-benchmark-misc.js | 12 +------- test/benchmark/test-benchmark-module.js | 10 +------ test/benchmark/test-benchmark-napi.js | 8 +----- test/benchmark/test-benchmark-net.js | 11 +------- test/benchmark/test-benchmark-os.js | 2 +- test/benchmark/test-benchmark-path.js | 9 +----- test/benchmark/test-benchmark-process.js | 7 +---- test/benchmark/test-benchmark-querystring.js | 7 +---- test/benchmark/test-benchmark-streams.js | 11 +------- .../test-benchmark-string_decoder.js | 5 +--- test/benchmark/test-benchmark-timers.js | 8 +----- test/benchmark/test-benchmark-tls.js | 14 +--------- test/benchmark/test-benchmark-url.js | 20 +------------ test/benchmark/test-benchmark-util.js | 15 +--------- test/benchmark/test-benchmark-v8.js | 7 +---- test/benchmark/test-benchmark-vm.js | 8 +----- test/benchmark/test-benchmark-worker.js | 11 +------- test/benchmark/test-benchmark-zlib.js | 15 +--------- 32 files changed, 34 insertions(+), 324 deletions(-) diff --git a/test/benchmark/test-benchmark-assert.js b/test/benchmark/test-benchmark-assert.js index 8a8ba0244489e5..5ec2319c28a15d 100644 --- a/test/benchmark/test-benchmark-assert.js +++ b/test/benchmark/test-benchmark-assert.js @@ -7,15 +7,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark( - 'assert', - [ - 'strict=1', - 'len=1', - 'method=', - 'n=1', - 'primitive=null', - 'size=1', - 'type=Int8Array' - ] -); +runBenchmark('assert'); diff --git a/test/benchmark/test-benchmark-async-hooks.js b/test/benchmark/test-benchmark-async-hooks.js index 662a6a07f313c7..c9ea2c1e86dbdf 100644 --- a/test/benchmark/test-benchmark-async-hooks.js +++ b/test/benchmark/test-benchmark-async-hooks.js @@ -10,13 +10,4 @@ if (!common.enoughTestMem) const runBenchmark = require('../common/benchmark'); -runBenchmark('async_hooks', - [ - 'asyncHooks=all', - 'connections=50', - 'method=trackingDisabled', - 'n=10', - 'type=async-resource', - 'asyncMethod=async' - ], - {}); +runBenchmark('async_hooks'); diff --git a/test/benchmark/test-benchmark-buffer.js b/test/benchmark/test-benchmark-buffer.js index 57130ffb08ba3d..af93842b0b92dd 100644 --- a/test/benchmark/test-benchmark-buffer.js +++ b/test/benchmark/test-benchmark-buffer.js @@ -4,30 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('buffers', - [ - 'aligned=true', - 'args=1', - 'buffer=fast', - 'bytes=0', - 'byteLength=1', - 'charsPerLine=6', - 'difflen=false', - 'encoding=utf8', - 'endian=BE', - 'extraSize=1', - 'len=256', - 'linesCount=1', - 'method=', - 'n=1', - 'partial=true', - 'pieces=1', - 'pieceSize=1', - 'search=@', - 'size=1', - 'source=array', - 'type=', - 'value=0', - 'withTotalLength=0' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('buffers', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-child-process.js b/test/benchmark/test-benchmark-child-process.js index 365777069bc4cf..043620de12f165 100644 --- a/test/benchmark/test-benchmark-child-process.js +++ b/test/benchmark/test-benchmark-child-process.js @@ -4,12 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('child_process', - [ - 'dur=0', - 'n=1', - 'len=1', - 'params=1', - 'methodName=execSync', - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('child_process', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-cluster.js b/test/benchmark/test-benchmark-cluster.js index 26df7ec239a221..b24aced5d58dc3 100644 --- a/test/benchmark/test-benchmark-cluster.js +++ b/test/benchmark/test-benchmark-cluster.js @@ -4,9 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('cluster', [ - 'n=1', - 'payload=string', - 'sendsPerBroadcast=1', - 'serialization=json', -]); +runBenchmark('cluster'); diff --git a/test/benchmark/test-benchmark-crypto.js b/test/benchmark/test-benchmark-crypto.js index 6ba71471cf4be2..7f6988acf234d8 100644 --- a/test/benchmark/test-benchmark-crypto.js +++ b/test/benchmark/test-benchmark-crypto.js @@ -10,18 +10,4 @@ if (common.hasFipsCrypto) const runBenchmark = require('../common/benchmark'); -runBenchmark('crypto', - [ - 'algo=sha256', - 'api=stream', - 'cipher=', - 'keylen=1024', - 'len=1', - 'n=1', - 'out=buffer', - 'size=1', - 'type=buf', - 'v=crypto', - 'writes=1', - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('crypto', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-dgram.js b/test/benchmark/test-benchmark-dgram.js index 8c93cd5a0c9239..ceafdd77a2aa80 100644 --- a/test/benchmark/test-benchmark-dgram.js +++ b/test/benchmark/test-benchmark-dgram.js @@ -4,14 +4,7 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -// Because the dgram benchmarks use hardcoded ports, this should be in -// sequential rather than parallel to make sure it does not conflict with -// tests that choose random available ports. +// Dgram benchmarks use hardcoded ports. Thus, this test can not be run in +// parallel with tests that choose random ports. -runBenchmark('dgram', ['address=true', - 'chunks=2', - 'dur=0.1', - 'len=1', - 'n=1', - 'num=1', - 'type=send']); +runBenchmark('dgram'); diff --git a/test/benchmark/test-benchmark-dns.js b/test/benchmark/test-benchmark-dns.js index 811e9a44b9e358..331a4c8ff0d85d 100644 --- a/test/benchmark/test-benchmark-dns.js +++ b/test/benchmark/test-benchmark-dns.js @@ -4,6 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -const env = { ...process.env, NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }; - -runBenchmark('dns', ['n=1', 'all=false', 'name=127.0.0.1'], env); +runBenchmark('dns', { ...process.env, NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-domain.js b/test/benchmark/test-benchmark-domain.js index e7d8b60b716441..5ebbfc5ea3b4db 100644 --- a/test/benchmark/test-benchmark-domain.js +++ b/test/benchmark/test-benchmark-domain.js @@ -4,4 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('domain', ['n=1', 'args=0']); +runBenchmark('domain'); diff --git a/test/benchmark/test-benchmark-es.js b/test/benchmark/test-benchmark-es.js index 47fe4ab3f91a63..6886b3ce925746 100644 --- a/test/benchmark/test-benchmark-es.js +++ b/test/benchmark/test-benchmark-es.js @@ -4,15 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('es', - [ - 'method=', - 'count=1', - 'context=null', - 'rest=0', - 'mode=', - 'n=1', - 'encoding=ascii', - 'size=1e1' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('es', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-events.js b/test/benchmark/test-benchmark-events.js index 06be60a84abb5b..53de4897dd75d2 100644 --- a/test/benchmark/test-benchmark-events.js +++ b/test/benchmark/test-benchmark-events.js @@ -4,6 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('events', - ['argc=0', 'listeners=1', 'n=1'], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('events', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-fs.js b/test/benchmark/test-benchmark-fs.js index cf382407235304..3ef6be2b7ebaed 100644 --- a/test/benchmark/test-benchmark-fs.js +++ b/test/benchmark/test-benchmark-fs.js @@ -6,19 +6,4 @@ const runBenchmark = require('../common/benchmark'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); -runBenchmark('fs', [ - 'bufferSize=32', - 'concurrent=1', - 'dir=.github', - 'dur=0.1', - 'encodingType=buf', - 'filesize=1024', - 'len=1024', - 'mode=callback', - 'n=1', - 'pathType=relative', - 'size=1', - 'statSyncType=fstatSync', - 'statType=fstat', - 'withFileTypes=false', -], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('fs', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-http.js b/test/benchmark/test-benchmark-http.js index 43531ec51cced7..a3d92c7e987f58 100644 --- a/test/benchmark/test-benchmark-http.js +++ b/test/benchmark/test-benchmark-http.js @@ -11,27 +11,4 @@ if (!common.enoughTestMem) const runBenchmark = require('../common/benchmark'); -runBenchmark('http', - [ - 'benchmarker=test-double-http', - 'arg=string', - 'c=1', - 'chunkedEnc=true', - 'chunks=0', - 'dur=0.1', - 'e=0', - 'input=keep-alive', - 'key=""', - 'len=1', - 'method=write', - 'n=1', - 'res=normal', - 'type=asc', - 'url=long', - 'value=X-Powered-By', - 'w=0', - ], - { - NODEJS_BENCHMARK_ZERO_ALLOWED: 1, - duration: 0 - }); +runBenchmark('http', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-http2.js b/test/benchmark/test-benchmark-http2.js index 1668a7b87fe643..25dd771076e758 100644 --- a/test/benchmark/test-benchmark-http2.js +++ b/test/benchmark/test-benchmark-http2.js @@ -13,17 +13,4 @@ if (!common.enoughTestMem) const runBenchmark = require('../common/benchmark'); -runBenchmark('http2', - [ - 'benchmarker=test-double-http2', - 'clients=1', - 'length=65536', - 'n=1', - 'nheaders=0', - 'requests=1', - 'streams=1' - ], - { - NODEJS_BENCHMARK_ZERO_ALLOWED: 1, - duration: 0 - }); +runBenchmark('http2', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-misc.js b/test/benchmark/test-benchmark-misc.js index 13bd41e54016f5..30707bfaf7366e 100644 --- a/test/benchmark/test-benchmark-misc.js +++ b/test/benchmark/test-benchmark-misc.js @@ -4,14 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('misc', [ - 'concat=0', - 'dur=0.1', - 'method=', - 'n=1', - 'type=', - 'code=1', - 'val=magyarország.icom.museum', - 'script=test/fixtures/semicolon', - 'mode=worker' -], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('misc', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-module.js b/test/benchmark/test-benchmark-module.js index 4d49ed249c392f..da8e108d53e19f 100644 --- a/test/benchmark/test-benchmark-module.js +++ b/test/benchmark/test-benchmark-module.js @@ -4,12 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('module', [ - 'cache=true', - 'dir=rel', - 'ext=', - 'fullPath=true', - 'n=1', - 'name=/', - 'useCache=true', -]); +runBenchmark('module'); diff --git a/test/benchmark/test-benchmark-napi.js b/test/benchmark/test-benchmark-napi.js index 1a1ff23d60c5c0..5c6a8aa01187ea 100644 --- a/test/benchmark/test-benchmark-napi.js +++ b/test/benchmark/test-benchmark-napi.js @@ -15,10 +15,4 @@ if (process.features.debug) { } const runBenchmark = require('../common/benchmark'); -runBenchmark('napi', - [ - 'n=1', - 'engine=v8', - 'type=String' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('napi', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-net.js b/test/benchmark/test-benchmark-net.js index f51c615b5df4f0..df8ea8011693ee 100644 --- a/test/benchmark/test-benchmark-net.js +++ b/test/benchmark/test-benchmark-net.js @@ -8,13 +8,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('net', - [ - 'dur=0', - 'len=1024', - 'recvbufgenfn=false', - 'recvbuflen=0', - 'sendchunklen=256', - 'type=buf' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('net', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-os.js b/test/benchmark/test-benchmark-os.js index 836e0e650483f1..dbedd7f582d90b 100644 --- a/test/benchmark/test-benchmark-os.js +++ b/test/benchmark/test-benchmark-os.js @@ -4,4 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('os', ['n=1']); +runBenchmark('os'); diff --git a/test/benchmark/test-benchmark-path.js b/test/benchmark/test-benchmark-path.js index 890fd7ae41f548..3bca4f2a11bd9d 100644 --- a/test/benchmark/test-benchmark-path.js +++ b/test/benchmark/test-benchmark-path.js @@ -4,11 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('path', - [ - 'n=1', - 'path=', - 'pathext=', - 'paths=', - 'props=' - ], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('path', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-process.js b/test/benchmark/test-benchmark-process.js index a73fc075bfcfa6..c6687f3023412b 100644 --- a/test/benchmark/test-benchmark-process.js +++ b/test/benchmark/test-benchmark-process.js @@ -4,9 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('process', - [ - 'n=1', - 'type=raw', - 'operation=enumerate', - ], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('process', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-querystring.js b/test/benchmark/test-benchmark-querystring.js index 77d0ac99ff97d8..6fee9bb39143ab 100644 --- a/test/benchmark/test-benchmark-querystring.js +++ b/test/benchmark/test-benchmark-querystring.js @@ -4,9 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('querystring', - [ 'n=1', - 'input="there is nothing to unescape here"', - 'type=noencode' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('querystring', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-streams.js b/test/benchmark/test-benchmark-streams.js index fa61b8dc4e0ae7..68c8478a7398c5 100644 --- a/test/benchmark/test-benchmark-streams.js +++ b/test/benchmark/test-benchmark-streams.js @@ -4,13 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('streams', - [ - 'kind=duplex', - 'n=1', - 'sync=no', - 'writev=no', - 'callback=no', - 'type=buffer', - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('streams', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-string_decoder.js b/test/benchmark/test-benchmark-string_decoder.js index f2fd6abe4b8f5f..721529e5ae64b1 100644 --- a/test/benchmark/test-benchmark-string_decoder.js +++ b/test/benchmark/test-benchmark-string_decoder.js @@ -4,7 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('string_decoder', ['chunkLen=16', - 'encoding=utf8', - 'inLen=32', - 'n=1']); +runBenchmark('string_decoder'); diff --git a/test/benchmark/test-benchmark-timers.js b/test/benchmark/test-benchmark-timers.js index af3c49bd714742..db4927ab32ea19 100644 --- a/test/benchmark/test-benchmark-timers.js +++ b/test/benchmark/test-benchmark-timers.js @@ -4,10 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('timers', - [ - 'direction=start', - 'n=1', - 'type=depth', - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('timers', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-tls.js b/test/benchmark/test-benchmark-tls.js index 264fa08d396be7..c9a87c15770d63 100644 --- a/test/benchmark/test-benchmark-tls.js +++ b/test/benchmark/test-benchmark-tls.js @@ -14,16 +14,4 @@ if (!common.enoughTestMem) const runBenchmark = require('../common/benchmark'); -runBenchmark('tls', - [ - 'concurrency=1', - 'dur=0.1', - 'n=1', - 'size=1024', - 'securing=SecurePair', - 'type=buf' - ], - { - NODEJS_BENCHMARK_ZERO_ALLOWED: 1, - duration: 0 - }); +runBenchmark('tls', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-url.js b/test/benchmark/test-benchmark-url.js index 8560c918fd1c69..664e7c4d8dc827 100644 --- a/test/benchmark/test-benchmark-url.js +++ b/test/benchmark/test-benchmark-url.js @@ -4,22 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('url', - [ - 'method=legacy', - 'e=0', - 'loopMethod=forEach', - 'accessMethod=get', - 'type=short', - 'searchParam=noencode', - 'href=short', - 'input=short', - 'domain=empty', - 'path=up', - 'to=ascii', - 'prop=href', - 'n=1', - 'param=one', - 'withBase=false' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('url', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-util.js b/test/benchmark/test-benchmark-util.js index b66d4fdb9b4cf6..d0c16c623268a6 100644 --- a/test/benchmark/test-benchmark-util.js +++ b/test/benchmark/test-benchmark-util.js @@ -4,17 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('util', - ['argument=false', - 'input=', - 'method=Array', - 'n=1', - 'option=none', - 'pos=start', - 'size=1', - 'type=', - 'len=1', - 'version=native', - 'isProxy=1', - 'showProxy=1'], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('util', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-v8.js b/test/benchmark/test-benchmark-v8.js index 22861785db9c05..efeaac8328c76d 100644 --- a/test/benchmark/test-benchmark-v8.js +++ b/test/benchmark/test-benchmark-v8.js @@ -4,9 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('v8', - [ - 'method=getHeapStatistics', - 'n=1' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('v8', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-vm.js b/test/benchmark/test-benchmark-vm.js index 79ab6a03402522..e9c4e3f1389f69 100644 --- a/test/benchmark/test-benchmark-vm.js +++ b/test/benchmark/test-benchmark-vm.js @@ -4,10 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('vm', - [ - 'breakOnSigint=0', - 'withSigintListener=0', - 'n=1' - ], - { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('vm', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-worker.js b/test/benchmark/test-benchmark-worker.js index ae9a8a6701ae4a..a4319d4face623 100644 --- a/test/benchmark/test-benchmark-worker.js +++ b/test/benchmark/test-benchmark-worker.js @@ -11,13 +11,4 @@ if (!common.enoughTestMem) const runBenchmark = require('../common/benchmark'); -runBenchmark('worker', - [ - 'n=1', - 'sendsPerBroadcast=1', - 'workers=1', - 'payload=string' - ], - { - NODEJS_BENCHMARK_ZERO_ALLOWED: 1 - }); +runBenchmark('worker', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/benchmark/test-benchmark-zlib.js b/test/benchmark/test-benchmark-zlib.js index adc7e3d47b040d..e3c4723aa9722f 100644 --- a/test/benchmark/test-benchmark-zlib.js +++ b/test/benchmark/test-benchmark-zlib.js @@ -4,17 +4,4 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('zlib', - [ - 'algorithm=brotli', - 'chunkLen=1024', - 'duration=0.001', - 'inputLen=1024', - 'method=', - 'n=1', - 'options=true', - 'type=Deflate', - ], - { - 'NODEJS_BENCHMARK_ZERO_ALLOWED': 1 - }); +runBenchmark('zlib', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); From 64a94642020a29bae34a367a0a86b84894eaa5aa Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 12 Feb 2020 21:02:35 +0100 Subject: [PATCH 4/6] Revert "Revert "benchmark: remove special test entries"" This reverts commit 7cfbc9f90f3109feaeb9db5df9d4d692a62178ef. --- benchmark/assert/deepequal-buffer.js | 4 +--- benchmark/assert/deepequal-map.js | 2 -- benchmark/assert/deepequal-object.js | 5 +---- benchmark/assert/deepequal-prims-and-objs-big-array-set.js | 2 -- benchmark/assert/deepequal-prims-and-objs-big-loop.js | 4 +--- benchmark/assert/deepequal-set.js | 2 -- benchmark/assert/deepequal-typedarrays.js | 2 -- benchmark/assert/throws.js | 2 -- benchmark/buffers/buffer-bytelength.js | 4 ++-- benchmark/buffers/buffer-creation.js | 1 - benchmark/buffers/buffer-fill.js | 2 +- benchmark/buffers/buffer-iterate.js | 2 +- benchmark/buffers/buffer-read-float.js | 1 - benchmark/buffers/buffer-read-with-byteLength.js | 2 +- benchmark/buffers/buffer-read.js | 2 +- benchmark/buffers/buffer-swap.js | 2 +- benchmark/buffers/buffer-write.js | 2 +- benchmark/buffers/dataview-set.js | 1 - benchmark/crypto/aes-gcm-throughput.js | 3 --- benchmark/crypto/cipher-stream.js | 6 +----- benchmark/es/defaultparams-bench.js | 2 -- benchmark/es/destructuring-bench.js | 2 -- benchmark/es/destructuring-object-bench.js | 2 -- benchmark/es/foreach-bench.js | 2 -- benchmark/es/map-bench.js | 2 -- benchmark/es/restparams-bench.js | 2 -- benchmark/es/spread-assign.js | 2 -- benchmark/es/spread-bench.js | 2 -- benchmark/es/string-concatenations.js | 2 -- benchmark/es/string-repeat.js | 2 -- benchmark/misc/arguments.js | 2 -- benchmark/misc/getstringwidth.js | 2 -- benchmark/misc/object-property-bench.js | 2 -- benchmark/misc/punycode.js | 2 -- benchmark/misc/trace.js | 1 - benchmark/misc/util-extend-vs-object-assign.js | 4 ---- benchmark/url/url-format.js | 2 +- benchmark/url/url-parse.js | 2 +- benchmark/util/format.js | 3 +-- benchmark/util/inspect-array.js | 2 -- benchmark/util/type-check.js | 3 --- 41 files changed, 15 insertions(+), 81 deletions(-) diff --git a/benchmark/assert/deepequal-buffer.js b/benchmark/assert/deepequal-buffer.js index 6d9162f15173f9..69cca91cc6d752 100644 --- a/benchmark/assert/deepequal-buffer.js +++ b/benchmark/assert/deepequal-buffer.js @@ -6,12 +6,10 @@ const bench = common.createBenchmark(main, { n: [2e4], len: [1e2, 1e3], strict: [0, 1], - method: [ 'deepEqual', 'notDeepEqual' ], + method: ['deepEqual', 'notDeepEqual'], }); function main({ len, n, method, strict }) { - if (!method) - method = 'deepEqual'; const data = Buffer.allocUnsafe(len + 1); const actual = Buffer.alloc(len); const expected = Buffer.alloc(len); diff --git a/benchmark/assert/deepequal-map.js b/benchmark/assert/deepequal-map.js index b88ecf7ce127f9..77408e3d103475 100644 --- a/benchmark/assert/deepequal-map.js +++ b/benchmark/assert/deepequal-map.js @@ -34,8 +34,6 @@ function main({ n, len, method, strict }) { const array = Array(len).fill(1); switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': { const values = array.map((_, i) => [`str_${i}`, 123]); benchmark(strict ? deepStrictEqual : deepEqual, n, values); diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index e23f6692b3decd..a8c539426a8156 100644 --- a/benchmark/assert/deepequal-object.js +++ b/benchmark/assert/deepequal-object.js @@ -7,7 +7,7 @@ const bench = common.createBenchmark(main, { n: [5e3], size: [1e2, 1e3, 5e4], strict: [0, 1], - method: [ 'deepEqual', 'notDeepEqual' ], + method: ['deepEqual', 'notDeepEqual'], }); function createObj(source, add = '') { @@ -27,9 +27,6 @@ function main({ size, n, method, strict }) { // TODO: Fix this "hack". `n` should not be manipulated. n = Math.min(Math.ceil(n / size), 20); - if (!method) - method = 'deepEqual'; - const source = Array.apply(null, Array(size)); const actual = createObj(source); const expected = createObj(source); diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js index 0e0ce450bb1a98..ad049ded02ce9d 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js @@ -52,8 +52,6 @@ function main({ n, len, primitive, method, strict }) { const expectedWrongSet = new Set(expectedWrong); switch (method) { - // Empty string falls through to next line as default, mostly for tests. - case '': case 'deepEqual_Array': run(strict ? deepStrictEqual : deepEqual, n, actual, expected); break; diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js index 32140f08ded6fb..2d01431b1fc563 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js @@ -13,12 +13,10 @@ const bench = common.createBenchmark(main, { primitive: Object.keys(primValues), n: [2e4], strict: [0, 1], - method: [ 'deepEqual', 'notDeepEqual' ], + method: ['deepEqual', 'notDeepEqual'], }); function main({ n, primitive, method, strict }) { - if (!method) - method = 'deepEqual'; const prim = primValues[primitive]; const actual = prim; const expected = prim; diff --git a/benchmark/assert/deepequal-set.js b/benchmark/assert/deepequal-set.js index 561a951e6834cc..27ca7c92bce1b0 100644 --- a/benchmark/assert/deepequal-set.js +++ b/benchmark/assert/deepequal-set.js @@ -34,8 +34,6 @@ function main({ n, len, method, strict }) { const array = Array(len).fill(1); switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': { const values = array.map((_, i) => `str_${i}`); benchmark(strict ? deepStrictEqual : deepEqual, n, values); diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 10ba21a25759e2..188cfce695ed61 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -20,8 +20,6 @@ const bench = common.createBenchmark(main, { }); function main({ type, n, len, method, strict }) { - if (!method) - method = 'deepEqual'; const clazz = global[type]; const actual = new clazz(len); const expected = new clazz(len); diff --git a/benchmark/assert/throws.js b/benchmark/assert/throws.js index c80518377a8742..978ad2f1b8bef0 100644 --- a/benchmark/assert/throws.js +++ b/benchmark/assert/throws.js @@ -15,8 +15,6 @@ function main({ n, method }) { const message = 'failure'; switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'doesNotThrow': bench.start(); for (let i = 0; i < n; ++i) { diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index 1b324a49f89de8..fbbe0f040da56a 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -17,9 +17,9 @@ const chars = [ function main({ n, len, encoding }) { let strings = []; - let results = [ len * 16 ]; + let results = [len * 16]; if (encoding === 'buffer') { - strings = [ Buffer.alloc(len * 16, 'a') ]; + strings = [Buffer.alloc(len * 16, 'a')]; } else { for (const string of chars) { // Strings must be built differently, depending on encoding diff --git a/benchmark/buffers/buffer-creation.js b/benchmark/buffers/buffer-creation.js index 38d80da915c070..862bff4fbabe58 100644 --- a/benchmark/buffers/buffer-creation.js +++ b/benchmark/buffers/buffer-creation.js @@ -16,7 +16,6 @@ const bench = common.createBenchmark(main, { function main({ len, n, type }) { let fn, i; switch (type) { - case '': case 'fast-alloc': fn = Buffer.alloc; break; diff --git a/benchmark/buffers/buffer-fill.js b/benchmark/buffers/buffer-fill.js index 02bc2a206c6fe3..8d4d4996068224 100644 --- a/benchmark/buffers/buffer-fill.js +++ b/benchmark/buffers/buffer-fill.js @@ -22,7 +22,7 @@ function main({ n, type, size }) { const buffer = Buffer.allocUnsafe(size); const testFunction = new Function('b', ` for (var i = 0; i < ${n}; i++) { - b.${type || 'fill(0)'}; + b.${type}; } `); bench.start(); diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index de002108a95d65..3e2a897903d435 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -21,7 +21,7 @@ function main({ size, type, method, n }) { Buffer.alloc(size) : SlowBuffer(size).fill(0); - const fn = methods[method || 'for']; + const fn = methods[method]; bench.start(); fn(buffer, n); diff --git a/benchmark/buffers/buffer-read-float.js b/benchmark/buffers/buffer-read-float.js index e8c4f8bf549628..656762d1d4f1d0 100644 --- a/benchmark/buffers/buffer-read-float.js +++ b/benchmark/buffers/buffer-read-float.js @@ -9,7 +9,6 @@ const bench = common.createBenchmark(main, { }); function main({ n, type, endian, value }) { - type = type || 'Double'; const buff = Buffer.alloc(8); const fn = `read${type}${endian}`; const values = { diff --git a/benchmark/buffers/buffer-read-with-byteLength.js b/benchmark/buffers/buffer-read-with-byteLength.js index 6ba1594b8ac6eb..c51ab11ae986d7 100644 --- a/benchmark/buffers/buffer-read-with-byteLength.js +++ b/benchmark/buffers/buffer-read-with-byteLength.js @@ -19,7 +19,7 @@ function main({ n, buf, type, byteLength }) { const buff = buf === 'fast' ? Buffer.alloc(8) : require('buffer').SlowBuffer(8); - const fn = `read${type || 'IntBE'}`; + const fn = `read${type}`; buff.writeDoubleLE(0, 0); bench.start(); diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 2ddca60df44c29..e0ec13992c2fae 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -28,7 +28,7 @@ function main({ n, buf, type }) { const buff = buf === 'fast' ? Buffer.alloc(8) : require('buffer').SlowBuffer(8); - const fn = `read${type || 'UInt8'}`; + const fn = `read${type}`; buff.writeDoubleLE(0, 0); bench.start(); diff --git a/benchmark/buffers/buffer-swap.js b/benchmark/buffers/buffer-swap.js index 5c31d86f7e2ab4..e43957efbdb095 100644 --- a/benchmark/buffers/buffer-swap.js +++ b/benchmark/buffers/buffer-swap.js @@ -76,7 +76,7 @@ function genMethod(method) { function main({ method, len, n, aligned = 'true' }) { const buf = createBuffer(len, aligned === 'true'); - const bufferSwap = genMethod(method || 'swap16'); + const bufferSwap = genMethod(method); bufferSwap(n, buf); bench.start(); diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index db5a57d0023e72..5025dd2bca0407 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -74,7 +74,7 @@ function main({ n, buf, type }) { const buff = buf === 'fast' ? Buffer.alloc(8) : require('buffer').SlowBuffer(8); - const fn = `write${type || 'UInt8'}`; + const fn = `write${type}`; if (!/\d/.test(fn)) benchSpecialInt(buff, fn, n); diff --git a/benchmark/buffers/dataview-set.js b/benchmark/buffers/dataview-set.js index a741d11356ea32..b7914fe45f175b 100644 --- a/benchmark/buffers/dataview-set.js +++ b/benchmark/buffers/dataview-set.js @@ -40,7 +40,6 @@ const mod = { }; function main({ n, type }) { - type = type || 'Uint8'; const ab = new ArrayBuffer(8); const dv = new DataView(ab, 0, 8); const le = /LE$/.test(type); diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index b1b08c481700ea..3f2b9ba45eb3f2 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -9,9 +9,6 @@ const bench = common.createBenchmark(main, { }); function main({ n, len, cipher }) { - // Default cipher for tests. - if (cipher === '') - cipher = 'aes-128-gcm'; const message = Buffer.alloc(len, 'b'); const key = crypto.randomBytes(keylen[cipher]); const iv = crypto.randomBytes(12); diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index 9f4a1bb4fa3d40..47a8931a540447 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { writes: [500], - cipher: [ 'AES192', 'AES256' ], + cipher: ['AES192', 'AES256'], type: ['asc', 'utf', 'buf'], len: [2, 1024, 102400, 1024 * 1024], api: ['legacy', 'stream'] @@ -12,9 +12,6 @@ const bench = common.createBenchmark(main, { }); function main({ api, cipher, type, len, writes }) { - // Default cipher for tests. - if (cipher === '') - cipher = 'AES192'; if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { console.error('Crypto streams not available until v0.10'); // Use the legacy, just so that we can compare them. @@ -29,7 +26,6 @@ function main({ api, cipher, type, len, writes }) { alice.generateKeys(); bob.generateKeys(); - const pubEnc = /^v0\.[0-8]/.test(process.version) ? 'binary' : null; const alice_secret = alice.computeSecret(bob.getPublicKey(), pubEnc, 'hex'); const bob_secret = bob.computeSecret(alice.getPublicKey(), pubEnc, 'hex'); diff --git a/benchmark/es/defaultparams-bench.js b/benchmark/es/defaultparams-bench.js index ab9cc45749c996..fde4cb11ad448a 100644 --- a/benchmark/es/defaultparams-bench.js +++ b/benchmark/es/defaultparams-bench.js @@ -36,8 +36,6 @@ function runDefaultParams(n) { function main({ n, method }) { switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'withoutdefaults': runOldStyleDefaults(n); break; diff --git a/benchmark/es/destructuring-bench.js b/benchmark/es/destructuring-bench.js index f1b484bd47e08f..c07c0383da91ac 100644 --- a/benchmark/es/destructuring-bench.js +++ b/benchmark/es/destructuring-bench.js @@ -36,8 +36,6 @@ function runSwapDestructured(n) { function main({ n, method }) { switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'swap': runSwapManual(n); break; diff --git a/benchmark/es/destructuring-object-bench.js b/benchmark/es/destructuring-object-bench.js index 68dc17073badc2..29c83bd188e89d 100644 --- a/benchmark/es/destructuring-object-bench.js +++ b/benchmark/es/destructuring-object-bench.js @@ -33,8 +33,6 @@ function runDestructured(n) { function main({ n, method }) { switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'normal': runNormal(n); break; diff --git a/benchmark/es/foreach-bench.js b/benchmark/es/foreach-bench.js index 88bfed00fbc27c..6992a1a5749438 100644 --- a/benchmark/es/foreach-bench.js +++ b/benchmark/es/foreach-bench.js @@ -54,8 +54,6 @@ function main({ n, count, method }) { items[i] = i; switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'for': fn = useFor; break; diff --git a/benchmark/es/map-bench.js b/benchmark/es/map-bench.js index 1b3ba4789db073..d0b8534cf7c906 100644 --- a/benchmark/es/map-bench.js +++ b/benchmark/es/map-bench.js @@ -104,8 +104,6 @@ function runMap(n) { function main({ n, method }) { switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'object': runObject(n); break; diff --git a/benchmark/es/restparams-bench.js b/benchmark/es/restparams-bench.js index d568e28744541f..8129bc92533332 100644 --- a/benchmark/es/restparams-bench.js +++ b/benchmark/es/restparams-bench.js @@ -51,8 +51,6 @@ function runUseArguments(n) { function main({ n, method }) { let fn; switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'copy': fn = runCopyArguments; break; diff --git a/benchmark/es/spread-assign.js b/benchmark/es/spread-assign.js index 97a5c5458e396b..970512aa6b93d4 100644 --- a/benchmark/es/spread-assign.js +++ b/benchmark/es/spread-assign.js @@ -18,8 +18,6 @@ function main({ n, context, count, rest, method }) { let obj; // eslint-disable-line no-unused-vars switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case '_extend': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/es/spread-bench.js b/benchmark/es/spread-bench.js index fc56c9433f2add..ae5b4abbb99c02 100644 --- a/benchmark/es/spread-bench.js +++ b/benchmark/es/spread-bench.js @@ -32,8 +32,6 @@ function main({ n, context, count, rest, method }) { args[i] = i; switch (method) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'apply': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/es/string-concatenations.js b/benchmark/es/string-concatenations.js index 72fb7f9969b604..3c0b27e05019d1 100644 --- a/benchmark/es/string-concatenations.js +++ b/benchmark/es/string-concatenations.js @@ -23,8 +23,6 @@ function main({ n, mode }) { let string; switch (mode) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'multi-concat': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/es/string-repeat.js b/benchmark/es/string-repeat.js index 9e33e4acf47118..f4bd616e4ada4b 100644 --- a/benchmark/es/string-repeat.js +++ b/benchmark/es/string-repeat.js @@ -18,8 +18,6 @@ function main({ n, size, encoding, mode }) { let str; switch (mode) { - case '': - // Empty string falls through to next line as default, mostly for tests. case 'Array': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/misc/arguments.js b/benchmark/misc/arguments.js index 8fefe617a51d56..39f4020b1ad20e 100644 --- a/benchmark/misc/arguments.js +++ b/benchmark/misc/arguments.js @@ -34,8 +34,6 @@ function usingPredefined() { function main({ n, method, args }) { let fn; switch (method) { - // '' is a default case for tests - case '': case 'restAndSpread': fn = usingRestAndSpread; break; diff --git a/benchmark/misc/getstringwidth.js b/benchmark/misc/getstringwidth.js index c10f7af8483cf9..9dd4b47df7182e 100644 --- a/benchmark/misc/getstringwidth.js +++ b/benchmark/misc/getstringwidth.js @@ -10,8 +10,6 @@ const bench = common.createBenchmark(main, { }); function main({ n, type }) { - // Default value for testing purposes. - type = type || 'ascii'; const { getStringWidth } = require('internal/util/inspect'); const str = ({ diff --git a/benchmark/misc/object-property-bench.js b/benchmark/misc/object-property-bench.js index 0a4d004999ed23..9b33ac9a636889 100644 --- a/benchmark/misc/object-property-bench.js +++ b/benchmark/misc/object-property-bench.js @@ -64,8 +64,6 @@ function runSymbol(n) { function main({ n, method }) { switch (method) { - // '' is a default case for tests - case '': case 'property': runProperty(n); break; diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js index 5f85df758ef7e3..9c674b5deefb8c 100644 --- a/benchmark/misc/punycode.js +++ b/benchmark/misc/punycode.js @@ -62,8 +62,6 @@ function runICU(n, val) { function main({ n, val, method }) { switch (method) { - // '' is a default case for tests - case '': case 'punycode': runPunycode(n, val); break; diff --git a/benchmark/misc/trace.js b/benchmark/misc/trace.js index f06e8597cc30e9..8620e99329b224 100644 --- a/benchmark/misc/trace.js +++ b/benchmark/misc/trace.js @@ -41,7 +41,6 @@ function main({ n, method }) { } = common.binding('trace_events'); switch (method) { - case '': case 'trace': doTrace(n, trace); break; diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js index b3d95f0e2d97a4..83aec7b9c82231 100644 --- a/benchmark/misc/util-extend-vs-object-assign.js +++ b/benchmark/misc/util-extend-vs-object-assign.js @@ -9,10 +9,6 @@ const bench = common.createBenchmark(main, { }); function main({ n, type }) { - // Default value for tests. - if (type === '') - type = 'extend'; - let fn; if (type === 'extend') { fn = util._extend; diff --git a/benchmark/url/url-format.js b/benchmark/url/url-format.js index 3e91cefd363c37..be5632d2b67367 100644 --- a/benchmark/url/url-format.js +++ b/benchmark/url/url-format.js @@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, { }); function main({ type, n }) { - const input = inputs[type] || ''; + const input = inputs[type]; // Force-optimize url.format() so that the benchmark doesn't get // disrupted by the optimizer kicking in halfway through. diff --git a/benchmark/url/url-parse.js b/benchmark/url/url-parse.js index 751a11201b11e2..b3e83188b2192f 100644 --- a/benchmark/url/url-parse.js +++ b/benchmark/url/url-parse.js @@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, { }); function main({ type, n }) { - const input = inputs[type] || ''; + const input = inputs[type]; bench.start(); for (let i = 0; i < n; i += 1) diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 976e0f4e655486..f7a6caa81c96b6 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -23,8 +23,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, type }) { - // For testing, if supplied with an empty type, default to string. - const [first, second] = inputs[type || 'string']; + const [first, second] = inputs[type]; bench.start(); for (let i = 0; i < n; i++) { diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js index 4fd73785f789d1..987b40479184d2 100644 --- a/benchmark/util/inspect-array.js +++ b/benchmark/util/inspect-array.js @@ -23,8 +23,6 @@ function main({ n, len, type }) { opts = { showHidden: true }; arr = arr.fill('denseArray'); break; - // For testing, if supplied with an empty type, default to denseArray. - case '': case 'denseArray': arr = arr.fill('denseArray'); break; diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js index 8d57bc000afcd1..792f61cf6fb217 100644 --- a/benchmark/util/type-check.js +++ b/benchmark/util/type-check.js @@ -35,9 +35,6 @@ const bench = common.createBenchmark(main, { }); function main({ type, argument, version, n }) { - // For testing, if supplied with an empty type, default to ArrayBufferView. - type = type || 'ArrayBufferView'; - const util = common.binding('util'); const types = require('internal/util/types'); From 626a7bf1204f26d37a5306693e25a4afa7caf656 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 12 Feb 2020 19:34:12 +0100 Subject: [PATCH 5/6] fixup: "benchmark: add `test` and `all` options and improve errors" --- benchmark/_http-benchmarkers.js | 11 +++++++---- benchmark/async_hooks/async-resource-vs-destroy.js | 13 ++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index b1b0038435d0c9..d0f192e75948b6 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -57,10 +57,13 @@ class WrkBenchmarker { } create(options) { + const duration = typeof options.duration === 'number' ? + Math.max(options.duration, 1) : + options.duration; const args = [ - '-d', options.duration, + '-d', duration, '-c', options.connections, - '-t', 8, + '-t', Math.min(options.connections, require('os').cpus().length || 8), `http://127.0.0.1:${options.port}${options.path}`, ]; for (const field in options.headers) { @@ -96,8 +99,9 @@ class TestDoubleBenchmarker { } create(options) { + process.env.duration = process.env.duration || options.duration || 5; + const env = { - duration: options.duration, test_url: `http://127.0.0.1:${options.port}${options.path}`, ...process.env }; @@ -213,7 +217,6 @@ exports.run = function(options, callback) { 'is not installed')); return; } - process.env.duration = process.env.duration || options.duration || 5; const benchmarker_start = process.hrtime(); diff --git a/benchmark/async_hooks/async-resource-vs-destroy.js b/benchmark/async_hooks/async-resource-vs-destroy.js index c9b9a81c5b7c7f..da0b52afa0ec40 100644 --- a/benchmark/async_hooks/async-resource-vs-destroy.js +++ b/benchmark/async_hooks/async-resource-vs-destroy.js @@ -13,14 +13,12 @@ const { } = require('async_hooks'); const { createServer } = require('http'); -// Configuration for the http server -// there is no need for parameters in this test -const connections = 500; -const path = '/'; - const bench = common.createBenchmark(main, { type: ['async-resource', 'destroy', 'async-local-storage'], asyncMethod: ['callbacks', 'async'], + path: '/', + connections: 500, + duration: 5, n: [1e6] }); @@ -165,7 +163,7 @@ const asyncMethods = { 'async': getServeAwait }; -function main({ type, asyncMethod }) { +function main({ type, asyncMethod, connections, duration, path }) { const { server, close } = types[type](asyncMethods[asyncMethod]); server @@ -174,7 +172,8 @@ function main({ type, asyncMethod }) { bench.http({ path, - connections + connections, + duration }, () => { close(); }); From 778b2a6ea4b572bee088f7ab8a36a8bb3ab9da7d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 13 Feb 2020 19:58:21 +0100 Subject: [PATCH 6/6] fixup: address comment --- benchmark/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/run.js b/benchmark/run.js index eae990ce5b2566..c2e38ce96d7895 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -60,7 +60,7 @@ if (format === 'csv') { for (const key of Object.keys(data.conf)) { if (conf !== '') conf += ' '; - conf += ` ${key}=${JSON.stringify(data.conf[key])}`; + conf += `${key}=${JSON.stringify(data.conf[key])}`; } if (format === 'csv') { // Escape quotes (") for correct csv formatting