MatthewMueller/cheerio — pull request #314 by jugglinmike (2013-11-30 23:02:34+00:00)
Title: Introduce rudimentary benchmark suite

@MatthewMueller [mentioned the need for benchmarks in a recent pull
request](https://github.com/MatthewMueller/cheerio/pull/309#issuecomment-29142449),
so I thought I would try to put together a simple suite. (This should also help
us to come to a formal decision on GitHub issue #182.)

The tests are run using [Benchmark.js](http://benchmarkjs.com/), and Cheerio's
performance is compared to analogous code in
[jsdom](https://github.com/tmpvar/jsdom) and jQuery. (I considered also
comparing [PhantomJS](http://phantomjs.org/), but since that runs in its own
process, it will be difficult to make an accurate performance measurement.)

I'm open to ideas about the kinds of tests we need to run and how we compare
statistics. For instance, it might be nice to compare Cheerio's performance at
two different git refs, but this will take a lot of additional work (the runner
would need to be able to do a lot of command-line work, including git
`checkout`s and NPM `install`s).

Here's what it looks like to run it:

$ make bench
Test: Select all (file: jquery.html)
cheerio x 82.17 ops/sec ±0.89% (73 runs sampled)
jsdom x 97.78 ops/sec ±0.22% (86 runs sampled)
Fastest: jsdom

Test: Toggle class (file: jquery.html)
cheerio x 318 ops/sec ±2.56% (91 runs sampled)
jsdom x 86.32 ops/sec ±0.57% (76 runs sampled)
Fastest: cheerio

Test: Select some (file: jquery.html)
cheerio x 1,076 ops/sec ±1.43% (97 runs sampled)
jsdom x 90.51 ops/sec ±0.22% (80 runs sampled)
Fastest: cheerio

Test: Create markup (file: jquery.html)
cheerio x 1,677 ops/sec ±17.12% (29 runs sampled)
jsdom x 230 ops/sec ±1.31% (86 runs sampled)
Fastest: cheerio

Commit message:

> Compare the performance of Cheerio at HEAD with jsdom [1] using jQuery.
> Include a new GNU Make target: `bench`.
>
> [1] https://github.com/tmpvar/jsdom