csnover/dojo2-teststack — pull request #39 by kitsonk (2013-03-31 16:21:09+00:00)
Title: Add benchmarking/performance API

I have finally gotten the integration of BenchmarkJS into something that I think is worth considering as a pull request.

The API offers to main varieties of suites. There is the "baseline" which will run every test and output metrics for each test. Then there is the "benchmark" which will compare several tests and output which one is the fastest and the slowest. Right now only the console reporter understands the appropriate topics for the suites.

A simple test would look something like this:

```js
define(['teststack!bench'], function (bench) {
bench.baseline('some baseline stats', function () {
bench.test('a test', function () {
// waste some cycles
});
});
bench.benchmark('comare something', function () {
bench.test('a way', function () {
// waste some cycles a way
});
bench.test('b way', function () {
// waste some cycles b way
});
bench.test('c way', function () {
// waste some cycles c way
});
});
});
```

The `bench.test()` passes through the arguments to BenchmarkJS, so individual tests can be configured to take advantage of the BenchmarkJS API directly (like individual pre-cycle setup and teardown) which is demonstrated in my [paser benchmark test](https://github.com/kitsonk/d2-proto/blob/master/test/parser/benchmark.js).

Refs csnover/dojo2-teststack#1.