You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's amazingly slower, as you always hit an await. On my machine (linux, node 14), it's 32x slower in a tight loop.
const bench = require('nanobench');
const ES = require('event-loop-spinner/dist/event-loop-spinner').EventLoopSpinner;
bench('spin recommended', async function (b) {
b.start()
const spinner = new ES(9000);
for (let i = 0; i < 2_000_000; i++) {
if (spinner.isStarving()) {
await spinner.spin();
}
}
b.end()
})
bench('spin function', async function (b) {
b.start()
const spinner = new ES(9000);
for (let i = 0; i < 2_000_000; i++) {
await gabssnake(spinner);
}
b.end()
})
async function gabssnake(spinner) {
if (spinner.isStarving()) return;
await spinner.spin();
}
NANOBENCH version 2
> /usr/bin/node spinner.js
# spin recommended
ok ~91 ms (0 s + 91346194 ns)
# spin function
ok ~2.92 s (2 s + 918358811 ns)
all benchmarks completed
ok ~3.01 s (3 s + 9705005 ns)
Hi, thanks for this and the related article!
Was wondering why you picked a two-step API instead of a single step?
Is there any significant penalty?
Usage:
For example:
The text was updated successfully, but these errors were encountered: