mathiasbynens/jsperf.com

setup / teardown not run exactly once per test

Closed this issue · 1 comments

Test test case: http://jsperf.com/setup-and-teardown-test

If you examine the console logs, it seems that for the first few iterations, setup and teardown are called before and after each test iteration, but then at some point setup will get called once, then the test will run many times before teardown is called.

This is really unexpected, and makes writing setup / teardown pretty awkward.

FYI this is on Ubuntu, Chrome 30.0.1599.22 beta

This is by design. Benchmark.js/jsPerf uses adaptive cycles. It does a test run, then cycles until it meets the minimum time to get an accurate reading.

It looks something like

<setup>
while (count--) {
<test>
}
<teardown>

If you are creating elements for a test to remove you can use the this.count which is the iteration count for the while loop.