-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: do not put closures on the queue (#57)
This makes the benchmarks slightly faster than version 5.0.0, and way faster than version 6.0.0
- Loading branch information
1 parent
f8ced5e
commit 8fd7a02
Showing
3 changed files
with
146 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
const throat = require('./index'); | ||
|
||
const MAX_COUNT = 1000000; | ||
const ITERATIONS = 10; | ||
const promises = []; | ||
for (let i = 0; i < 1000000; i++) { | ||
promises.push(() => new Promise(resolve => process.nextTick(resolve))); | ||
for (let i = 0; i < MAX_COUNT; i++) { | ||
promises.push(() => new Promise((resolve) => process.nextTick(resolve))); | ||
} | ||
|
||
Promise.resolve().then(async () => { | ||
for (let amount = 10; amount <= 1000000; amount = amount * 10) { | ||
console.log('limit=10'); | ||
for (let amount = 10; amount <= MAX_COUNT; amount = amount * 10) { | ||
const list = promises.slice(0, amount); | ||
console.time(amount + ' promises'); | ||
await Promise.all(list.map(throat(10, fn => fn()))); | ||
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'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters