benchmark: refactor benchmark/assert/throws.js
This is a minor refactor of benchmark/assert/throws.js to reduce exceptions that need to be made for lint compliance. PR-URL: https://github.com/nodejs/node/pull/21030 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
b8f8ca5702
commit
f86e5fc437
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common.js');
|
||||
const assert = require('assert');
|
||||
const { throws, doesNotThrow } = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e6],
|
||||
@ -14,8 +14,8 @@ const bench = common.createBenchmark(main, {
|
||||
});
|
||||
|
||||
function main({ n, method }) {
|
||||
const throws = () => { throw new TypeError('foobar'); };
|
||||
const doesNotThrow = () => { return 'foobar'; };
|
||||
const throwError = () => { throw new TypeError('foobar'); };
|
||||
const doNotThrowError = () => { return 'foobar'; };
|
||||
const regExp = /foobar/;
|
||||
const message = 'failure';
|
||||
var i;
|
||||
@ -26,30 +26,28 @@ function main({ n, method }) {
|
||||
case 'doesNotThrow':
|
||||
bench.start();
|
||||
for (i = 0; i < n; ++i) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
assert.doesNotThrow(doesNotThrow);
|
||||
doesNotThrow(doNotThrowError);
|
||||
}
|
||||
bench.end(n);
|
||||
break;
|
||||
case 'throws':
|
||||
bench.start();
|
||||
for (i = 0; i < n; ++i) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
assert.throws(throws);
|
||||
throws(throwError);
|
||||
}
|
||||
bench.end(n);
|
||||
break;
|
||||
case 'throws_TypeError':
|
||||
bench.start();
|
||||
for (i = 0; i < n; ++i) {
|
||||
assert.throws(throws, TypeError, message);
|
||||
throws(throwError, TypeError, message);
|
||||
}
|
||||
bench.end(n);
|
||||
break;
|
||||
case 'throws_RegExp':
|
||||
bench.start();
|
||||
for (i = 0; i < n; ++i) {
|
||||
assert.throws(throws, regExp, message);
|
||||
throws(throwError, regExp, message);
|
||||
}
|
||||
bench.end(n);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user