-
Notifications
You must be signed in to change notification settings - Fork 334
Promise support #176
Comments
@garkin I mention that in the above description. |
I'll try to create a pull request for this. I really need this feature in a high-level benchmarking library I'm creating. |
Recognising |
For anyone looking for a quick copy/paste fix: function p(fn) {
return {
defer: true,
async fn(deferred) {
await fn();
deferred.resolve();
}
}
} Usage: const wait = ms => new Promise(res => setTimeout(res, ms));
new Suite()
.add('An async perf test', p(async () => {
await wait(1000);
}))
.on('cycle', ev => console.log(String(ev.target)))
.run(); |
I forked benchmark.js and i would actually say that determining If the Return value is a Promise is not reliable imho. But we can determine if the function is an async function and then wrap defer object around it. |
Am I misunderstanding the problem here or can this be solved by using |
Async means that the benchmarking is delayed by 0.05 seconds or so. It does not mean, that promises work or so. You have some callback/Promise resolve logic possible if you use defer: true and in the benchmark you resolve the deferred object. You can checkout my fork callled tinybench. It has async functionality, but it is painfully slower and gives not correct benchmark results for async. |
tinybench is working flawless now. |
Knock knock. |
Here is a small subclass that auto deferredifies async function benchmarks:
Adds a By default it wraps all functions that are not already For more control, i.e. if you want to have functions that return promises but are not waited or to avoid the overhead of Use in the obvious way:
Naturally, all |
I dont see that you set delay to 0 in your snippet |
@Uzlopak The |
Would be much nicer to be able to return a promise in a suite than having to manually call
deferred.resolve()
.This is what we currently have to do:
This is what I would like:
In the next major version, I would also remove the
async
anddefer
option and just be async if the bench function returns a Promise, otherwise synchronous.// @jdalton @floatdrop
Context: https://github.com/sindresorhus/p-queue/pull/4/files#diff-bf2f25928a0b46d29e7743d11b05f999R8
The text was updated successfully, but these errors were encountered: