Skip to content

Conversation

@rubennorte
Copy link
Contributor

@rubennorte rubennorte commented Dec 21, 2024

It also validates that all the hooks (beforeAll, beforeEach, etc.) are synchronous as well and makes the benchmark fail if any of them is async (returns a promise-like object).

I did a slight refactor to extract logic common to both sync and async, and duplicated the tests that made sense to test for flavors.

closes #202

Copy link
Collaborator

@jerome-benoit jerome-benoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good at a first glance.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 21, 2024

Open in Stackblitz

npm i https://pkg.pr.new/tinylibs/tinybench@210

commit: 34b1feb

@jerome-benoit jerome-benoit changed the title Add runSync method to Bench to force benchmarks to be synchronous feat: add runSync method to Bench to force benchmarks to be synchronous Dec 21, 2024
src/bench.ts Outdated
runSync (): Task[] {
if (this.concurrency != null) {
throw new Error('Cannot use `concurrency` option when using `runSync`')
}
Copy link
Collaborator

@jerome-benoit jerome-benoit Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do the same for the runSync method in the Task class and we're good to go (yes, it's bad to have Task exported not only as a type but unfortunately the API have already been widely abused)

Copy link
Collaborator

@jerome-benoit jerome-benoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to land

@jerome-benoit jerome-benoit self-assigned this Dec 23, 2024
@jerome-benoit jerome-benoit added the enhancement New feature or request label Dec 23, 2024
@jerome-benoit jerome-benoit merged commit c4ddb46 into tinylibs:main Dec 23, 2024
15 checks passed
@rubennorte rubennorte deleted the sync-mode branch December 23, 2024 10:47
@rubennorte
Copy link
Contributor Author

Thanks for the reviews, @jerome-benoit !!

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for synchronous benchmarks

2 participants