Detalhes do pacote

matcha

Benchmark your code.

readme (leia-me)

Matcha

A caffeine driven, simple approach to benchmarking.

Matcha allow you to design experiments that will measure the performance of your code. It is recommended that each bench focus on a specific point of impact in your application.

Matcha Report

Installation

Matcha is available on npm.

  $ npm install matcha

Writing Async Benchmarks

Though suites/benches are executed serially, the benches themselves can be asyncronous. Furthermore, suites ran with the matcha command line runner have a number of globals to simplify bench definitions. Take the following code, for example:

suite('Make Tea', function () {
  var tea = new CupOfTea('green');

  bench('boil water', function(next) {
    tea.boil('85℃', function (err, h20) {
      // perfect temperature!
      next();
    });
  });

  // add tea, pour, ...  

  bench('sip tea', function() {
    tea.sip('mmmm');
  });
});

Async vs. Sync

Since boiling water takes time, a next function was provided to each iteration in our bench to be called when the async function completes. Since the consumption of tea provides instant gratification, no next needed to be provided, even though we still wish to measure it.

Setup/Teardown

Arbitray functions may be specified for setup or teardown for each suite by using the before and after keywords. These function may be sync or async.

suite('DB', function() {
  before(function(next) {
    db.connect('localhost:9090', next);
  });

  bench(function(next) {
    // ...
  });

  after(function() {
    db.close();
  });
});

Setting Options

As not all code is equal, we need a way to change the running conditions for our benches. Options can currently be changed for any given suite, and will be retained for any nested suites or benches of that suite.

To set an option:

suite('Make Tea', function () {
  set('iterations', 10000);
  set('type', 'static');
  // ...
Defaults

Here are all available options and the default values:

set('iterations', 100);     // the number of times to run a given bench
set('concurrency', 1);      // the number of how many times a given bench is run concurrently
set('type', 'adaptive');    // or 'static' (see below)
set('mintime', 500);        // when adaptive, the minimum time in ms a bench should run
set('delay', 100);          // time in ms between each bench
Static vs Adaptive

There are two modes for running your benches: 'static' and 'adaptive'. Static mode will run exactly the set number of iterations. Adaptive will run the set iterations, then if a minimal time elapsed has not passed, will run more another set of iterations, then check again (and repeat) until the requirement has been satisfied.

Running Benchmarks

Running of your benchmarks is provided through ./bin/matcha. The recommended approach is to add a devDependancy in your package.json and then add a line to a Makefile or build tool. The matcha bin will accept a list of files to load or will look in the current working directory for a folder named benchmark and load all files.

  $ matcha suite1.js suite2.js

Options

    -h, --help               view matcha usage information
    -v, --version            view matcha version
    -R, --reporter [clean]   specify the reporter to use
    -I, --interface [bdd]    specify the interface to expect
    --interfaces             display available interfaces
    --reporters              display available reporters

-I, --interface <name>

The --interface option lets you specify the interface to use, defaulting to "bdd".

-R, --reporter <name>

The --reporter option allows you to specify the reporter that will be used, defaulting to "clean".

Interfaces

Matcha "interface" system allows developers to choose their style of DSL. Shipping with bdd, and exports flavoured interfaces.

bdd

suite('suite name', function(){
    set('iterations', 10);
    bench('bench name', function(done){
        some_fn(done);
  });
});

exports

exports['suite name'] = {
    options: {
      iterations: 10
    },
    bench: {
        'bench name': function (doen) {
            some_fn(done);
        }
    }
};

Reporters

Matcha reporters adjust to the terminal window.

clean

Good-looking default reporter with colors on the terminal screen.

plain

Similar to clean reporter but without colors and other ANSI sequences.

csv

Completely different, create csv formated rows for later processing.

Contributing

Interested in contributing? Fork to get started. Contact @logicalparadox if you are interested in being regular contributor.

Contibutors

Shoutouts

  • mocha inspired the suite/bench definition language.

License

(The MIT License)

Copyright (c) 2011-2012 Jake Luer jake@alogicalparadox.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

changelog (log de mudanças)

0.7.0 / 2016-03-07

  • Merge pull request #23 from addaleax/json-reporter
  • Merge pull request #21 from stevemao/patch-1
  • Add JSON reporter
  • update mocha link

0.6.1 / 2015-12-22

  • Merge pull request #18 from landau/patch-1
  • Use ops as ending value
  • add ops to csv output

0.6.0 / 2014-11-10

  • Merge pull request #17 from juliangruber/handle-errors
  • throw on error
  • Merge pull request #16 from rkusa/master
  • add concurrency options

0.5.0 / 2014-04-04

  • Merge pull request #13 from patrick-steele-idem/master
  • Store the stats with each bench to help reporters report the results
  • Added Patrick Steele-Idem as contributor
  • Simplified the reporter API and added support for third-party reporters

0.4.1 / 2013-12-02

  • Merge branch 'refactor/v8'
  • bin: v8-argv support
  • test: confirm can run single iteration. Closes #11
  • docs: before/after were undocumented. Closes #7
  • Merge pull request #10 from alexlande/patch-1
  • Replace simplistic with simple in readme

0.4.0 / 2013-10-15

  • Merge pull request #8 from visionmedia/add/harmony
  • add support for some v8 flags including --harmony

0.3.0 / 2013-08-12

  • reporter: [csv ] small tweaks
  • reporter: [plain] small tweaks
  • deps: [electron] update version tag
  • example: [async] errors on node 10
  • Merge pull request #5 from vavere/master
  • update readme
  • add help about available interfaces/reporters
  • add csv reporter
  • add plain text reporter
  • Merge pull request #4 from domenic/patch-1
  • Small fixes to make more pleasant on Windows
  • bin checks for existence of default benchmark folder if no files provided
  • code cleanup for runner and comments
  • comments for suite

0.2.0 / 2012-07-24

  • add async bench example + cleanup
  • fix bug for async bench improper sequence of events
  • improvide code consistency for interface
  • further cleaning of utils
  • remove unused utils
  • comment updates for timer
  • provide date based timer for node < 0.8.x
  • remove progress event listeners from reporters
  • suite code cleanup
  • bench code cleanup
  • refactor series helper and update runner to comply
  • Merge branch 'refactor/bench-timers'
  • bench is using timer, not Date
  • Merge branch 'refactor/reporter'
  • comment cleanup
  • finish modulizing reporter system to open up for more!
  • Merge branch 'master' into refactor/reporter
  • Merge branch 'feature/timers'
  • add node high res timer constructor
  • begin reporter refactor - folder organization
  • Merge branch 'refactor/interface'
  • add export interface style and a bit more commenting to existing
  • refactor interfaces to use an interface manager
  • Merge pull request #2 from domenic/patch-1
  • Add xsuite and xbench for temporarily disabling benchmarks.
  • Merge branch 'feature/cli'
  • refactor cli to use electron
  • more sample benchmarks
  • main cli router
  • match update
  • bench onprogess looks for options in the right place

0.1.1 / 2012-01-29

  • update screenshot
  • bench refactored to be a lot more efficient (and less taxing on stats), especially when running adaptively
  • clean up existence example
  • fonder naming complete
  • standard deviation util
  • folder rearrange
  • bench holds own options + code cleanup
  • i'll have typos for 1000, thanks
  • README typos

0.1.0 / 2012-01-29

  • README
  • sane defaults
  • few small cli things
  • default reporter finished
  • make reports presentable
  • foot suite completed event and reporting
  • correct folder benchmark not benchmarks
  • reporting tweaks
  • before / after support in suite/bench/runner
  • before and after in sample benchmarks
  • adding some variation to the included benchmarks
  • bench detects runnable fn is async by using function length
  • clean reporter
  • bench return more stats
  • bench list (results) event for runner
  • nested suite example
  • added clean reporter, main exports, clean up
  • broke up suite to allow for nesting … added runner
  • scrap crappy reporter
  • update interface to match intended style
  • teach bench how to count
  • added some utils
  • using optimist in binfile
  • update benchmarks to match intended style
  • git ignore vim stuffs
  • package updates

0.0.2 / 2011-12-06

  • bin does mocha style global pre-requires
  • static report includes memory
  • cli reports in ms
  • suite run provide callback
  • better sample benchmarks
  • bench events use spaces, not cameCase
  • sample test defaults
  • do series cleanup
  • sample benchmarks (temporary)
  • added bin file
  • name change
  • rename to matcha
  • damn exports

0.0.1 / 2011-12-05

  • package.json updates
  • first working version
  • project init