Browse Source

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>
v7.x
Vse Mozhet Byt 8 years ago
committed by Myles Borins
parent
commit
751c1153a4
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 3
      benchmark/common.js
  2. 3
      test/sequential/test-benchmark-net.js

3
benchmark/common.js

@ -193,6 +193,9 @@ Benchmark.prototype.end = function(operations) {
if (typeof operations !== 'number') { if (typeof operations !== 'number') {
throw new Error('called end() without specifying operation count'); 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 time = elapsed[0] + elapsed[1] / 1e9;
const rate = operations / time; const rate = operations / time;

3
test/sequential/test-benchmark-net.js

@ -15,7 +15,8 @@ const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 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) => { child.on('exit', (code, signal) => {
assert.strictEqual(code, 0); assert.strictEqual(code, 0);
assert.strictEqual(signal, null); assert.strictEqual(signal, null);

Loading…
Cancel
Save