Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Allow Asynchronous Calls in setup()/teardown() Functions #174

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

meanjoe45
Copy link

This pull request is in reference to issue #70. To start off, this is a breaking change. When the defer option is set to true for a benchmark, both the setup() and teardown() functions require their resolve functions be called (suResolve() and tdResolve() respectively). If the functions are not included with the benchmark, the resolve calls are generated allowing setup() and teardown() functions to be omitted.

I tried to maintain the coding style as you describe, but have no problem changing variable names and such if you feel something else works better.

Currently, the unit tests are updated and are all passing when run with Node.js v4.x. I'm not very versed in running with the browser, so I'd appreciate any assistance people are willing to provide to test out these changes more. This includes verifying that the accuracy of the benchmarks has not been compromised.

Please reference the unit tests for examples of use. Documentation will need to be updated, but wanted to get some validation these changes will be accepted before investing the time to document.

Thanks for all the work you've put into benchmark.js.

@meanjoe45
Copy link
Author

I have run the unit tests with Node.js v4.4.2 and v6.9.1 locally on my machine and everything passes. I'm not sure yet why the CI build failed. I'll try to investigate soon, but help is appreciated.

@shamasis
Copy link

@jdalton can we get this merged? this really a required feature where there is no option except async setup / teardown

@daprahamian
Copy link

Is there a reason this has not been merged yet?

@gwynjudd
Copy link
Contributor

@jdalton is there anything that can be done to merge this? This is a very useful patch for doing async setup/teardown. Do you want to consider changing it so the breaking nature of the change doesn't occur?

This fixes an issue I found when using benchmark and my library was minified. I don't really understand all of the implications, but what seems to have happened is that the line "deferred.suResolve()" errors as "deferred" was undefined in minified.

By inspection, I noted that similar code was using the "interpolate" function and replaced "#d" with the name of the deferred variable.
@shamasis
Copy link

@jdalton ping :-|

Fix benchmark tests when running with minified library code
@vflopes
Copy link

vflopes commented Aug 9, 2018

+1
This feature is really awesome and I really need (I think a lot of people too).
Waiting for release.

@rajsite
Copy link

rajsite commented Oct 9, 2018

We are trying to use benchmark.js for benchmarking the JS interface to some logic implemented in wasm and are also stuck because our wasm instantiation needs to happen asynchronously. Having async setup would definitely be helpful!

@jszwedko
Copy link

jszwedko commented Nov 20, 2019

Just bumping this as I ran into it today given the last movement was ~ a year ago. Is there anything that needs to change for this PR? I'm happy to try to pitch in.

@Feirell
Copy link

Feirell commented Aug 25, 2020

@jdalton just another ping, I would help out if there is still something to do to make this happen.

@timoxley
Copy link

Bump. This makes accurate async testing difficult

@Uzlopak
Copy link

Uzlopak commented Mar 9, 2022

I will adapt this change to my fork

@Finesse
Copy link

Finesse commented Feb 7, 2024

Waiting for the PR to be merged...

Awaiter

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.