Skip to content

mitata v1 - stable release

Compare
Choose a tag to compare
@evanwashere evanwashere released this 28 Sep 18:14
· 59 commits to master since this release

mitata

benchmark tooling that loves you ❤️


mitata is a powerful javascript benchmarking library with features like ascii visualizations, automatic garbage collection, universal runtime/engine compatibility, and high-resolution timings.

Quick Start

javascript c++ single header
import { run, bench, boxplot } from 'mitata';

function fibonacci(n) {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

bench('fibonacci(40)', () => fibonacci(40));

boxplot(() => {
  bench('new Array($size)', function* (state) {
    const size = state.get('size');
    yield () => Array.from({ length: size });
  }).range('size', 1, 1024);
});

await run();
#include "src/mitata.hpp"

int fibonacci(int n) {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

int main() {
  mitata::runner runner;
  runner.bench("noop", []() { });

  runner.summary([&]() {
    runner.bench("empty fn", []() { });
    runner.bench("fibonacci", []() { fibonacci(20); });
  });

  auto stats = runner.run();
}

breaking changes

simpler run options

await run({
  // throw errors immediately instead of handling them quietly
  throw: false,

  // filter benchmarks with regex
  filter: /.*/,

  // colored output (respects NO_COLOR)
  colors: true,

  // output format: quiet, json, or mitata
  format: 'mitata',
});

groups no longer have names and summary has been moved to dedicated function

import { bench, group, summary } from 'mitata';

group(() => {
  bench('...', () => {});
  bench('...', () => {});
});

summary(() => {
  bench('...', () => {});
  bench('...', () => {});
});

🚀 New Features

beautiful visualizations right in your terminal

mitata output has been completely revamped to take advantage of its new ascii rendering capabilities while still having zero dependencies.

-------------------------------------- -------------------------------
Bubble Sort               2.05 ms/iter   2.20 ms  ▂▇█▄                
                   (1.75 ms … 6.21 ms)   2.61 ms ▂█████▇▄▃▃▄▅█▄▃▃▂▃▂▁▁
Quick Sort              158.22 µs/iter 156.25 µs  █                   
               (135.38 µs … 685.29 µs) 545.29 µs ██▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
Native Sort              98.09 µs/iter  98.54 µs   █▇                 
                (94.21 µs … 136.71 µs) 111.58 µs ▁▄██▆▃▃▃▃▂▂▂▁▂▁▁▁▁▁▁▁

                        ┌                                            ┐
                                                      ╷ ┌──┬──┐      ╷
            Bubble Sort                               ├─┤  │  ├──────┤
                                                      ╵ └──┴──┘      ╵
                         ┬      ╷
             Quick Sort  │──────┤
                         ┴      ╵
                        ┬
            Native Sort │
                        ┴
                        └                                            ┘
                        94.21 µs            1.35 ms            2.61 ms

                        ┌                                            ┐
                  1 + 1 ┤■ 83.50 ps 
             Date.now() ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 27.30 ns 
                        └                                            ┘

                        ┌                                            ┐
      Array.from($size)                                            ⢠⠊ 2.02 µs
       new Array($size)                                          ⢀⠔⠁ 
                                                                ⡠⠃   
                                                              ⢀⠎     
                                                             ⡔⠁      
                                                           ⡠⠊        
                                                         ⢀⠜          
                                                        ⡠⠃           
                                                       ⡔⠁            
                                                     ⢀⠎              
                                                    ⡠⠃               
                                                  ⢀⠜                 
                                                 ⢠⠊                  
                                                ⡰⠁         ⢀⣀⣀⣀⡠⠤⠤⠤⠒⠒
                                           ⣀⣀⣀⠤⠜   ⢀⣀⡠⠤⠒⠒⠉⠉⠁         
                         ⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣔⣒⣒⣊⣉⠭⠤⠤⠤⠤⠤⠒⠒⠉⠁                  3.21 ns
                        └                                            ┘

untangling most common benchmarking spaghetti

mitata now allows you to skip all boilerplate code required for running same benchmark with different configurations.

import { bench, summary } from 'mitata';

bench('new URL($x)', () => {
  const url = state.get('x');
  yield () => new URL(url);
}).args(['https://example.com', 'https://example.com/foo?bar=baz']);

summary(() => {
  // names have special $ keys that get replaced with argument value
  bench('Array.from($size)', function* (state) {
    const size = state.get('size');
    yield () => Array.from({ length: size });
  }).range('size', 1, 1024);

  bench('new Array($size)', function* (state) {
    const size = state.get('size');
    yield () => new Array(size);
  }).range('size', 1, 1024);

  // summary
  //   new Array($len)
  //    5.59…8.68x faster than Array.from($len)
});

and more...

  • automatic garbage collection
  • accuracy down to picoseconds
  • lite version as c++ single-header file
  • clear warnings for optimized out benchmarks
  • compatible with v8, spidermonkey, JavaScriptCore, Graal.js, QuickJS, and more