Skip to content

The "setup" is not running after each test #90

Closed
simonsarris opened this Issue Jul 11, 2012 · 4 comments

3 participants

@simonsarris

Clearing canvas is cited as an example of using the "setup" section, but as you can see, the canvas doesn't actually get cleared:

http://jsperf.com/image-vs-text/5

Inside the first test is a fillText and fillRect call. When you click run, the text "lala" writes as more and more rectangles get drawn diagonally across the page. There should only be one rectangle at a time, though, because the setup function is ought to be clearing the canvas. But it isn't.

Am I missing something here, or is this a huge bug?

@jdalton
Collaborator
jdalton commented Jul 11, 2012

Not a huge bug. The setup works like this:

<setup>
while (testLoopCount--) {
  <test>
}
<teardown>
@jdalton jdalton closed this Jul 11, 2012
@simonsarris

Ah I see.

At the risk of being rude, the documentation seems unclear here. There seems to be no talk of how to execute something un-timed before each individual run of a singular test. Is that not possible?

@jdalton
Collaborator
jdalton commented Jul 11, 2012

At the risk of being rude, the documentation seems unclear here. There seems to be no talk of how to execute something un-timed before each individual run of a singular test. Is that not possible?

The setup and teardown are un-timed but the test loop is timed. It has to be in a test loop to run the test for the minimum amount of time for the resolution of the timer in use. So most browsers have a resolution of 1ms so the min time needed is 1 / 2 / 0.01 = 50ms.

@mathiasbynens
Owner

There seems to be no talk of how to execute something un-timed before each individual run of a singular test. Is that not possible?

No, that’s not possible. The best you can do is just add it to the test’s code and have it be the same for all tests, so it won’t influence the (relative) results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.