node/benchmark/assert/throws.js
Ruben Bridgewater bb6125bac7
benchmark: remove special test entries
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>
2020-03-09 22:35:54 +01:00

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}`);
}
}