benchmark: check end() argument to be > 0
PR-URL: https://github.com/nodejs/node/pull/12030 Ref: https://github.com/nodejs/node/issues/11972 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
66e7dc5587
commit
642baf4699
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user