Run simple performance tests.
npm install perfect --save
With perfect you can run simple performance tests to see which variations of a piece of code (f.e. different algos to achieve the same thing) are the fastest.
- The source is not transpiled for older browsers (yet) so you may have to transpile this in your own build setup.
See the examples.
The API looks like this:
performanceTest function will start a performance test right away
(synchronously). Async tests are not supported yet (they will be good for
testing async functionality like worker responses or network conditions).
Each test in
testCases will be executed as many times as specified by
iterations, which defaults to
test function of each test case is what the performance test is
interested in timing. Inside a
test function, call
specify exactly which part of the
test function we care about timing. If
end() are not called, then the performance test will time the
entire execution of the
test function. Calling
completely optional, but you may like to use them to get best results. If you
start(), then the timer will start from the beginning of the execution
test function. Likewise, if you omit
end(), then timing ends after
test has returned.
setup() function is called once, at the beginning of a testCase, before
any iterations call the
test function. In all functions,
this is a context
that you can use throughout all invocations of any functions. Use this in
setup() to set up anything that you may across all iterations of the
after are called during each iteration, before and after the
test function is called. This useful for resetting state, incrementing
cleanup is called once after interation has finished. Use this to
cleanup anything you no longer need, for example in case your tests are part of
a long running application and you don't want things to be left over in memory.
Plus, it can be nice to reset the playing field for each test case, if you need