-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathglobal-concurrent-tests.js
More file actions
53 lines (46 loc) · 1 KB
/
global-concurrent-tests.js
File metadata and controls
53 lines (46 loc) · 1 KB
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
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const common = require('../common');
const { it } = require('node:test');
const bench = common.createBenchmark(
main,
{
n: [100, 1000, 1e4],
type: ['sync', 'async'],
},
{
// We don't want to test the reporter here
flags: [
'--test-reporter=./benchmark/fixtures/empty-test-reporter.js',
'--test-reporter-destination=stdout',
],
},
);
async function run(n, type) {
const promises = new Array(n);
// eslint-disable-next-line no-unused-vars
let avoidV8Optimization;
switch (type) {
case 'sync': {
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, () => {
avoidV8Optimization = i;
});
}
break;
}
case 'async':
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, async () => {
avoidV8Optimization = i;
});
}
break;
}
await Promise.all(promises);
}
function main({ n, type }) {
bench.start();
run(n, type).then(() => {
bench.end(n);
});
}