(operations)
| 259 | } |
| 260 | |
| 261 | end(operations) { |
| 262 | // Get elapsed time now and do error checking later for accuracy. |
| 263 | const time = process.hrtime.bigint(); |
| 264 | |
| 265 | if (!this._started) { |
| 266 | throw new Error('called end without start'); |
| 267 | } |
| 268 | if (this._ended) { |
| 269 | throw new Error('called end multiple times'); |
| 270 | } |
| 271 | if (typeof operations !== 'number') { |
| 272 | throw new Error('called end() without specifying operation count'); |
| 273 | } |
| 274 | if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) { |
| 275 | throw new Error('called end() with operation count <= 0'); |
| 276 | } |
| 277 | |
| 278 | this._ended = true; |
| 279 | |
| 280 | if (time === this._time) { |
| 281 | if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED) |
| 282 | throw new Error('insufficient clock precision for short benchmark'); |
| 283 | // Avoid dividing by zero |
| 284 | this.report(operations && Number.MAX_VALUE, 0n); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | const elapsed = time - this._time; |
| 289 | const rate = operations / (Number(elapsed) / 1e9); |
| 290 | this.report(rate, elapsed); |
| 291 | } |
| 292 | |
| 293 | report(rate, elapsed) { |
| 294 | sendResult({ |
no test coverage detected