Skip to content

Commit a305ae2

Browse files
mscdexcodebytere
authored andcommitted
benchmark: check for and fix multiple end()
PR-URL: #31624 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 708aff9 commit a305ae2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

‎benchmark/common.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Benchmark(fn, configs, options){
3333
this._time=[0,0];
3434
// Used to make sure a benchmark only start a timer once
3535
this._started=false;
36+
this._ended=false;
3637

3738
// this._run will use fork() to create a new process for each configuration
3839
// combination.
@@ -197,6 +198,9 @@ Benchmark.prototype.end = function(operations){
197198
if(!this._started){
198199
thrownewError('called end without start');
199200
}
201+
if(this._ended){
202+
thrownewError('called end multiple times');
203+
}
200204
if(typeofoperations!=='number'){
201205
thrownewError('called end() without specifying operation count');
202206
}
@@ -210,6 +214,7 @@ Benchmark.prototype.end = function(operations){
210214
elapsed[1]=1;
211215
}
212216

217+
this._ended=true;
213218
consttime=elapsed[0]+elapsed[1]/1e9;
214219
constrate=operations/time;
215220
this.report(rate,elapsed);

‎benchmark/streams/writable-manywrites.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ function main({n, sync, writev, callback }){
3535
letk=0;
3636
functionrun(){
3737
while(k++<n&&s.write(b,cb));
38-
if(k>=n)
38+
if(k>=n){
3939
bench.end(n);
40+
s.removeListener('drain',run);
41+
}
4042
}
4143
s.on('drain',run);
4244
run();

0 commit comments

Comments
(0)