diff --git a/benchmark/common.js b/benchmark/common.js index 24369f2f543b67..77ebe0bd1dc37f 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -193,6 +193,9 @@ Benchmark.prototype.end = function(operations) { 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'); + } const time = elapsed[0] + elapsed[1] / 1e9; const rate = operations / time; diff --git a/test/sequential/test-benchmark-net.js b/test/sequential/test-benchmark-net.js index 4bb91451e9b254..826d891fd76621 100644 --- a/test/sequential/test-benchmark-net.js +++ b/test/sequential/test-benchmark-net.js @@ -15,7 +15,8 @@ const path = require('path'); const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); -const child = fork(runjs, ['--set', 'dur=0', 'net']); +const child = fork(runjs, ['--set', 'dur=0', 'net'], + {env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}}); child.on('exit', (code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(signal, null);