blob: 978ad2f1b8bef0b5f40fb50f375dbe967db1d3d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
'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}`);
}
}
|