-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
perf.js
29 lines (27 loc) · 949 Bytes
/
perf.js
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
const throat = require('./index');
const MAX_COUNT = 1000000;
const ITERATIONS = 10;
const promises = [];
for (let i = 0; i < MAX_COUNT; i++) {
promises.push(() => new Promise((resolve) => process.nextTick(resolve)));
}
Promise.resolve().then(async () => {
console.log('limit=10');
for (let amount = 10; amount <= MAX_COUNT; amount = amount * 10) {
const list = promises.slice(0, amount);
console.time(amount + ' promises');
for (let i = 0; i < ITERATIONS; i++) {
await Promise.all(list.map(throat(10, (fn) => fn())));
}
console.timeEnd(amount + ' promises');
}
console.log('limit=1000000');
for (let amount = 10; amount <= MAX_COUNT; amount = amount * 10) {
const list = promises.slice(0, amount);
console.time(amount + ' promises');
for (let i = 0; i < ITERATIONS; i++) {
await Promise.all(list.map(throat(1000000, (fn) => fn())));
}
console.timeEnd(amount + ' promises');
}
});