A caffeine driven, simplistic approach to benchmarking.

Related tags

Miscellaneous matcha
Overview

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

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

-R, --reporter

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 [email protected]

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.

Comments
  • Use process.hrtime()/window.performance.now() when available

    Use process.hrtime()/window.performance.now() when available

    process.hrtime() is a bit wacky, but window.performance.now() is pretty sane.

    Here is what I did for process.hrtime(), but I don't like it enough to submit a pull request. Just an idea.

    function elapsedMilliseconds(startHrtime) {
      var elapsedHrtime = process.hrtime(startHrtime);
      return elapsedHrtime[0] * 1000 + elapsedHrtime[1] / 1000 / 1000;
    }
    
    // Then do `start = process.hrtime()`, `elapsed = elapsedMilliseconds(start)`.
    
    opened by domenic 4
  • add support for some v8 flags including --harmony

    add support for some v8 flags including --harmony

    totally up to you I'm alright with using the fork, the "proxy" executable could be a shell script too. This might become common enough between executables that we may want to consider making it a real module that mocha/matcha/whatever can share

    opened by tj 3
  • Cannot read property 'length' of undefined

    Cannot read property 'length' of undefined

    Am I missing something?

    ./node_modules/.bin/matcha bench.js 
    child_process: customFds option is deprecated, use stdio instead.
    
                          test
                     wait » function () {
            test(25);
        }/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/bench.js:122
      var runner = this.fn.length === 0
                          ^
    TypeError: Cannot read property 'length' of undefined
        at Bench.runAdaptive (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/bench.js:122:23)
        at Bench.run (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/bench.js:67:10)
        at /Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/runner.js:125:11
        at iterate (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/utils.js:28:5)
        at exports.series (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/utils.js:37:3)
        at Runner.runBenches (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/runner.js:123:3)
        at iterator (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/runner.js:80:5)
        at iterate (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/utils.js:28:5)
        at cb (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/utils.js:30:26)
        at iterate (/Users/bbriggs/projects/test/node_modules/matcha/lib/matcha/utils.js:27:21)
    

    bench.js:

    function test (n) {
        return n * 5;
    }
    
    suite('test', function () {
        bench(function () {
            test(25);
        });
    });
    

    node version:

    node --version
    v0.12.2
    
    opened by ben-eb 2
  • add ops to csv output

    add ops to csv output

    As the title reads. This prop is missing from csv output. I simply copied the formatting and omitted humanize. I moved ops to be the ending value for the sake of compatibility.

    opened by landau 2
  • Simplified the reporter API and added support for third-party reporters

    Simplified the reporter API and added support for third-party reporters

    I removed the need for reporters to inherit from Base and moved all of the static methods that were part of Base into the utils module. The Runner now collects the common stats (# of suites, # of benches and elapsed time) and passes the stats to the reporter as the argument to the end event listeners. Each reporter now is simply a module that exports a function of the following form:

    module.exports = function(runner, utils) {
    }
    

    Lastly, I added support for using third-party reporters. Third-party reporters can either be installed via npm in the user's project or they can be referenced using a relative path that is considered relative to process.cwd(). For example:

    matcha templating-benchmarks.js --reporter ./my-custom-reporter
    

    Thanks for creating this module! I found it very helpful when building templating benchmarks: https://github.com/raptorjs3/templating-benchmarks

    I wanted to be able to easily report additional information--hence the need for this Pull Request.

    --Patrick

    opened by patrick-steele-idem 2
  • Bump electron from 0.4.1 to 7.1.0

    Bump electron from 0.4.1 to 7.1.0

    Bumps electron from 0.4.1 to 7.1.0.

    Release notes

    Sourced from electron's releases.

    electron v7.1.0

    Release Notes for v7.1.0

    Features

    • Added new contextBridge module to make it easier to communicate between an isolated context and the main world. #20789

    Fixes

    • Fixed nativeTheme not accessible via the remote module. #20961
    • Fixed a memory leak issue when setting Tray images. #20935
    • Fixed issue where proxied remote promises might not resolve if Bluebird was installed in the renderer. #20947

    Other Changes

    • Prepare for 7.1.0. 18176b48, ef548b65
    • Updated Chromium to 78.0.3904.94. #20930

    electron v7.0.1

    Release Notes for v7.0.1

    Fixes

    • Fixed shell.openExternal() option workingDirectory not working with Unicode characters. #20905
    • Fixed a crash in Menus related to menu.popup(). #20808
    • Fixed a label mismatch on open and save dialogs on GTK. #20882
    • Fixed a regression in the recentDocuments role on macOS. #20670
    • Fixed an issue where objects referenced by remote could sometimes not be correctly freed. #20693
    • Fixed crashes when calling webContents.printToPDF() multiple times. #20810
    • Fixed devtools extensions not loading due to "Connect to unknown extension [object Object]" errors. #20844
    • Fixed flicker when switching between BrowserViews. #20846
    • Fixed fs.mkdir/mkdirSync hang with {recursive: true} for invalid names with node 12 on windows. #20629
    • Fixed hang when closing a scriptable popup window using the remote module. #20715
    • Fixed memory leaks caused by callbacks not being released when the remote module is used in sub-frames (<iframe> or scriptable popup). #20814
    • Fixed native module size increase on windows, follow up fix to https://github-redirect.dependabot.com/electron/electron/pull/20614. #20708
    • Fixed several deprecation warnings in Electron code. #20804

    Other Changes

    • Updated Chromium to 78.0.3904.92. #20913

    Documentation

    • Documentation changes: #20757

    electron v7.0.0

    Release Notes for v7.0.0

    Notable Changes

    • Stack upgrades:
    ... (truncated)
    Commits
    Maintainer changes

    This version was pushed to npm by electron-nightly, a new releaser for electron since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  •  Use `process.cpuUsage()` instead of `process.hrtime()`

    Use `process.cpuUsage()` instead of `process.hrtime()`

    In benchmarking, the real world time is not suggested because the real world running time of a function is influenced by other running programs (like browsers, slates, Mail...). This PR use process.cpuUsage, counting only the cpu usage time and excluding the idling time.

    opened by zhujinxuan 0
  • Bump electron from 0.4.1 to 9.1.0

    Bump electron from 0.4.1 to 9.1.0

    Bumps electron from 0.4.1 to 9.1.0.

    Release notes

    Sourced from electron's releases.

    electron v9.1.0

    Release Notes for v9.1.0

    Features

    • Added support for MessagePort in the main process. #24323
    • Added support for suspend and resume events to Windows. #24283
    • Added support for suspend and resume events to macOS. #24294
    • Expose sessionId associated with a target from debugger module. #24398
    • Implemented systemPreferences.getMediaAccessStatus() on Windows. #24312

    Fixes

    • Fixed an intermittent high-CPU usage problem caused a system clock issue during sleep. #24415
    • Fixed an issue where some old notifications were not properly removed from the Notification Center on macOS. #24406
    • Fixed bug on macOS where the main window could be targeted for a focus event when it was disabled behind a modal. #24354

    electron v9.0.5

    Release Notes for v9.0.5

    Fixes

    • Fixed "Paste and Match Style" shortcut on macOS to match OS's "Option-Shift-Command-V". #24185
    • Fixed "null path-to-app" in test-app when Electron's path contains spaces or special characters. #24232
    • Fixed an error when calling dialog.showCertificateTrustDialog with no BrowserWindow. #24121
    • Fixed an issue where shutdown would be emitted both on app and system shutdown on macOS. #24141
    • Fixed an issue where withFileTypes was not supported as an option to fs.readdir or fs.readdirSync under asar. #24108
    • Fixed an issue which would cause streaming protocol responses to stall in some cases. #24082
    • Fixed an issue with click events not being emitted on macOS for Trays with context menus set. #24236
    • Fixed delayed execution of some Node.js callbacks in the main process. #24178
    • Fixed tray menu showing in taskbar on Windows. #24193
    • Fixed window titlebar not responding to pen on Windows 10. #24103

    Other Changes

    • Fixed issue with some IMEs on windows (for ex: Zhuyin) don't terminate after pressing shift. #24059
    • Fixed mac app store rejection notice for invalid symbolic link in bundle. #24238
    • Updated Chromium to 83.0.4103.119. #24234

    Documentation

    • Documentation changes: #24177

    electron v9.0.4

    Release Notes for v9.0.4

    Fixes

    • Added missing support for isComposing KeyboardEvent property. #23996
    • Enable NTLM v2 for POSIX platforms and added --disable-ntlm-v2 switch to disable it. #23934
    Commits
    Maintainer changes

    This version was pushed to npm by electron-nightly, a new releaser for electron since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Shim process.stdout.write for browserify compatibility

    Shim process.stdout.write for browserify compatibility

    It's possible to use matcha in the browser using browserify and testling. However, using the plain reporter is not possible because process.stdout.write is not supported. This change adds a fallback to the plain reporter.

    opened by Hypercubed 0
Owner
Jake Luer
Jake Luer
Javascript-testing-practical-approach-2021-course-v3 - Javascript Testing, a Practical Approach (v3)

Javascript Testing, a Practical Approach Description This is the reference repository with all the contents and the examples of the "Javascript Testin

Stefano Magni 2 Nov 14, 2022
A jQuery plugin that offers a simplistic way of implementing Lion OS scrollbars.

This project is not maintained This project is not currently actively maintained. If you need an up-to-date scrollbar plugin, try OverlayScrollbars in

James F 2.7k Nov 24, 2022
A benchmarking library. As used on jsPerf.com.

Benchmark.js v2.1.4 A robust benchmarking library that supports high-resolution timers & returns statistically significant results. As seen on jsPerf.

BestieJS Modules 5.3k Dec 28, 2022
Cross-runtime benchmarking lib and cli

mitata cross-runtime benchmarking lib Install bun add mitata npm install mitata Examples import { run, bench, group, baseline } from 'mitata'; // den

evan 165 Jan 3, 2023
🔎 A simple, tiny and lightweight benchmarking library!

tinybench Benchmark your code easily with Tinybench, a simple, tiny and light-weight 7KB (2KB minified and gzipped) benchmarking library! You can run

Tinylibs 516 Jan 9, 2023
'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Sihoon Kim 11 Jan 4, 2023
Composable data visualisation library for web with a data-first approach now powered by WebAssembly

What is Muze? Muze is a free data visualization library for creating exploratory data visualizations (like Tableau) in browser, using WebAssembly. It

Charts.com 1.2k Dec 29, 2022
:orange_book: simple approach for javascript localization

ttag ⚠️ This project was previously named c-3po. Some of the talks, presentations, and documentation may reference it with both names. Modern javascri

ttag 307 Jan 2, 2023
Open source rich text editor based on HTML5 and the progressive-enhancement approach. Uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.

This project isn’t maintained anymore Please check out this fork. wysihtml5 0.3.0 wysihtml5 is an open source rich text editor based on HTML5 technolo

Christopher Blum 6.5k Jan 7, 2023
Plain functions for a more functional Deku approach to creating stateless React components, with functional goodies such as compose, memoize, etc... for free.

"Keo" is the Vietnamese translation for glue. Plain functions for a more functional Deku approach to creating stateless React components, with functio

Adam Timberlake 225 Sep 24, 2022
Open source rich text editor based on HTML5 and the progressive-enhancement approach. Uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.

This project isn’t maintained anymore Please check out this fork. wysihtml5 0.3.0 wysihtml5 is an open source rich text editor based on HTML5 technolo

Christopher Blum 6.5k Dec 30, 2022
Full text search based on InvertedIndex and ordinary approach

The Node js project that has CRUD operation and has a FullTextSearch.

Ali Nowrouzi 5 Jul 15, 2022
A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast.

RESPRESS A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, ma

Yousef Wadi 9 Aug 29, 2022
🌿 A pace-layered approach to high-volume Discord Servers.

?? Steward The order of civilization. The fast layers innovate; the slow layers stabilize. The whole combines learning with continuity. -- Stewart Bra

Jacky Zhao 8 Mar 26, 2022
A novel approach for security and user experience of Graphical Password Authentication.

Graphical Password Authentication Alohomora Harry Potter themed (not really) Graphical Password Authentication Flowchart and Architecture Solution Dem

Akshat Shah 10 Dec 15, 2022
Modern approach to Low Quality Image Placeholders (LQIP) using webp and sharp.

lqip-modern Modern approach to Low Quality Image Placeholders (LQIP) using webp and sharp. (demo) This approach is extremely fast and produces much sm

Travis Fischer 187 Dec 30, 2022
📊 A highly interactive data-driven visualization grammar for statistical charts.

English | 简体中文 G2 A highly interactive data-driven visualization grammar for statistical charts. Website • Tutorial Docs • Blog • G2Plot G2 is a visua

AntV team 11.5k Dec 30, 2022
Relay is a JavaScript framework for building data-driven React applications.

Relay · Relay is a JavaScript framework for building data-driven React applications. Declarative: Never again communicate with your data store using a

Facebook 17.5k Jan 1, 2023