mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
d1ce04c592
PR-URL: https://github.com/nodejs/node/pull/30450 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const { throws, doesNotThrow } = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e4],
|
|
method: [ 'doesNotThrow', 'throws_TypeError', 'throws_RegExp' ],
|
|
});
|
|
|
|
function main({ n, method }) {
|
|
const throwError = () => { throw new TypeError('foobar'); };
|
|
const doNotThrowError = () => { return 'foobar'; };
|
|
const regExp = /foobar/;
|
|
const message = 'failure';
|
|
|
|
switch (method) {
|
|
case '':
|
|
// Empty string falls through to next line as default, mostly for tests.
|
|
case 'doesNotThrow':
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
doesNotThrow(doNotThrowError);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'throws_TypeError':
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
throws(throwError, TypeError, message);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'throws_RegExp':
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
throws(throwError, regExp, message);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
throw new Error(`Unsupported method ${method}`);
|
|
}
|
|
}
|