mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
bb6125bac7
This reverts commit 7cfbc9f90f
.
PR-URL: https://github.com/nodejs/node/pull/31755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 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 '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}`);
|
|
}
|
|
}
|