Skip to content

Commit

Permalink
benchmark: refactor benchmark/assert/throws.js
Browse files Browse the repository at this point in the history
This is a minor refactor of benchmark/assert/throws.js to
reduce exceptions that need to be made for lint compliance.

PR-URL: #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>
  • Loading branch information
Trott committed Jun 2, 2018
1 parent b8f8ca5 commit f86e5fc
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions benchmark/assert/throws.js
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f86e5fc

Please sign in to comment.