forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrejects.js
More file actions
34 lines (30 loc) · 795 Bytes
/
rejects.js
File metadata and controls
34 lines (30 loc) · 795 Bytes
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
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [2e5],
method: ['rejects', 'doesNotReject'],
}, {
combinationFilter(p) {
// These benchmarks purposefully do not run by default. They do not provide
// much insight, due to only being a small wrapper around a native promise
// with a few extra checks.
return p.n === 1;
},
});
async function main({ n, method }) {
const fn = assert[method];
const shouldReject = method === 'rejects';
bench.start();
for (let i = 0; i < n; ++i) {
await fn(async () => {
const err = new Error(`assert.${method}`);
if (shouldReject) {
throw err;
} else {
return err;
}
});
}
bench.end(n);
}