vitest icon indicating copy to clipboard operation
vitest copied to clipboard

feat: add hooks in bench mode

Open waynevanson opened this issue 10 months ago • 8 comments

Description

  1. This PR allows hooks to be used when running vitest bench.
  2. This is essentially an updated fork of #5076.
  3. Closes #5075.
  4. Creating this as we'd like to use hooks in benchmarks in https://github.com/ariakit/ariakit/pull/4415

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [x] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • [x] Ideally, include a test that fails without this PR but passes with it.
  • [x] Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • [x] Run the tests with pnpm test:ci.

Documentation

  • [ ] If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • [x] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

waynevanson avatar Feb 23 '25 07:02 waynevanson

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
Latest commit e621d3affac45afb67496b016dac06c26081ae0d
Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67bacc987853ef00086925b2
Deploy Preview https://deploy-preview-7541--vitest-dev.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Feb 23 '25 07:02 netlify[bot]

I spoke with a team member in the Discord and they mentioned that windows tests are flaky, even in main. That's why it's marked as ready for review.

waynevanson avatar Apr 16 '25 01:04 waynevanson

Is this still in limbo with flaky Windows tests? My team is chomping at the bit to start using this. 🥺

erunion avatar Jun 05 '25 04:06 erunion

Is this still in limbo with flaky Windows tests? My team is chomping at the bit to start using this. 🥺

I'll update the branch and see if there are still issues.

waynevanson avatar Jun 07 '25 07:06 waynevanson

Just to be clear, is this unrelated to https://tinylibs.github.io/tinybench/interfaces/FnOptions.html#beforeeach and https://tinylibs.github.io/tinybench/interfaces/FnOptions.html#aftereach which allows running code in every iteration that is not included in the total time?

The FnOptions are crucial to allow measuring anything that has a large setup time like setting up a db or a file system before each iteration.

arv avatar Jun 09 '25 08:06 arv

Just to be clear, is this unrelated to https://tinylibs.github.io/tinybench/interfaces/FnOptions.html#beforeeach and https://tinylibs.github.io/tinybench/interfaces/FnOptions.html#aftereach which allows running code in every iteration that is not included in the total time?

The FnOptions are crucial to allow measuring anything that has a large setup time like setting up a db or a file system before each iteration.

So you're concerned that the current implementation of our Vitest hooks will are part of the execution time? I think it would in it's current state and I don't believe it's what is intended. I can fix.

waynevanson avatar Jun 16 '25 08:06 waynevanson

So you're concerned that the current implementation of our Vitest hooks will are part of the execution time? I think it would in it's current state and I don't believe it's what is intended. I can fix.

I was actually more concerned that we are not exposing the tinybench setup/teardown and how they can be exposed in a consistent manner to vitest bench tasks.

arv avatar Jun 16 '25 08:06 arv

So you're concerned that the current implementation of our Vitest hooks will are part of the execution time? I think it would in it's current state and I don't believe it's what is intended. I can fix.

I was actually more concerned that we are not exposing the tinybench setup/teardown and how they can be exposed in a consistent manner to vitest bench tasks.

@arv They're already exposed I believe, as the second parameter in a Vitest benchmark. Just forwards the object to TinyBench.

Do you have a recommendation of how you'd imagine they should be exposed?

waynevanson avatar Jun 16 '25 08:06 waynevanson

Benchmarks being reimagined - I'll close this.

waynevanson avatar Nov 24 '25 10:11 waynevanson

@waynevanson is there a PR/issue I can follow?

arv avatar Nov 26 '25 13:11 arv

Yes @arv, github.com/vitest-dev/vitest/discussions/7850

I've also created this package to run tests as benchmarks which is currently in development. https://github.com/waynevanson/vitest-runner-benchmark

waynevanson avatar Nov 29 '25 05:11 waynevanson