tape-benchmark
Version:
Benchmarking functions for tape
72 lines (48 loc) • 2.08 kB
Markdown
# tape-benchmark
> Benchmarking functions for tape
```js
// Load tape into tape-benchmark:
var test = require('tape-benchmark')(require('tape'))
test('my-test', function (t) {
// plan and do your asserts here ...
// then create benchmark asserts:
t.benchmark('original', function () {
// ...
})
t.benchmark('variant', { minSamples: 100 }, function () {
// ...
})
})
```
This module wraps [`benchmark`](https://npmjs.com/package/benchmark) into [`tape`](https://npmjs.com/tape) asserts. So there is no setup between the two, and you get the same logging with both.
## Installation
```sh
$ npm install --save tape-benchmark
```
## Usage
### `load(tape)`
Load benchmark assertions onto tape
```js
// Load like this:
var test = require('tape-benchmark')(require('tape'))
// Or just like this:
require('tape-benchmark')(test)
```
### `t.benchmark(name, [options], fn)`
Run benchmark as an assertion. Passes with results, or fails with an error. Use `t.bench` as a shorthand.
```js
test('my-test', function (t) {
t.plan(2)
t.benchmark('original', function () {
(123).toString()
})
t.benchmark('binary', { minSamples: 100 }, function () {
(123).toString(2)
})
})
```
## License
MIT © [Jamen Marz](https://git.io/jamen)
---
[][package] [](https://travis-ci.org/tape-benchmark/jamen) [][package] [][package] [][package] [](https://www.paypal.me/jamenmarz/5usd) [](https://github.com/jamen)
[package]: https://npmjs.com/package/tape-benchmark