Skip to content

Setup for impure code #36

@caderek

Description

@caderek

@kirbysayshi suggested:

As I'm looking through the other cases for setup, the common pattern seems to be that the setup is run once, completely outside of benchmark.js (this makes sense since it doesn't support async setup). But there could be a deeper concern here too: only running the setup function once could result in inconsistent start state for the clocked function:

add('array truncation', async () => {
  const arr = (new Array(1000)).fill(true);
  return async () => {
    // on the first run, this will actually truncate the array.
    // on subsequent runs, the length would already be zero since the setup state is shared.
    arr.length = 0;
  }
})

I open this issue to reconsider this behavior for impure functions that can mutate setup.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions