Skip to content

Commit 642baf4

Browse files
committed
benchmark: check end() argument to be > 0
PR-URL: #12030 Ref: #11972 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 66e7dc5 commit 642baf4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

benchmark/common.js

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ Benchmark.prototype.end = function(operations) {
193193
if (typeof operations !== 'number') {
194194
throw new Error('called end() without specifying operation count');
195195
}
196+
if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) {
197+
throw new Error('called end() with operation count <= 0');
198+
}
196199

197200
const time = elapsed[0] + elapsed[1] / 1e9;
198201
const rate = operations / time;

test/sequential/test-benchmark-net.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const path = require('path');
1515

1616
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
1717

18-
const child = fork(runjs, ['--set', 'dur=0', 'net']);
18+
const child = fork(runjs, ['--set', 'dur=0', 'net'],
19+
{env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}});
1920
child.on('exit', (code, signal) => {
2021
assert.strictEqual(code, 0);
2122
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)