/chai-performance

a few extra language features to test performance using chai

Primary LanguageJavaScriptMIT LicenseMIT

chai-performance

js-standard-style npm version

Performance test plugin for the chai assertion libary, for the browser and node

var chai = require('chai')
var perf = require('chai-performance')
chai.use(perf)

// use this to enable or disable logs on success (enabled by default in node)
perf.log = true

describe('chai-performance', function () {
  it('division should be as fast as multiplication', function (done) {
    this.timeout(50e3)
    var amount = 1e6
    expect(function () {
      for (var i = 0, j; i < amount; i++) {
        j = i * 10
      }
    }).performance({
      margin: 1,
      loop:10,
      method: function () {
        for (var i = 0, j; i < amount; i++) {
          j = i / 10
        }
      }
    }, done)
  })
})