Skip to content

Releases: evanwashere/mitata

mitata november update

20 Nov 21:48
Compare
Choose a tag to compare

🛠️ Changes

groups can have names

group(name, () => {
  ...
});

 math
-------------------------------------------
1 + 1                         87.43 ps/iter
                       (51.03 ps  9.83 ns)

charts/visualizations can be nested and combined

summary(() => {
  barplot(() => {
    bench(...);
  });

  barplot(() => { ... });
});

------------------------------------------- -------------------------------
1 + 1                        105.54 ps/iter  91.55 ps                     !
                       (61.04 ps  1.83 µs) 122.07 ps ▁▁▁▁▁▁▁█▁▁█▁▁▁▁▁▁▄▁▁▂
Date.now()                    39.61 ns/iter  28.01 ns                     
                       (27.83 ns  3.19 µs) 153.12 ns █▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                                                                         
                       1 + 1  105.54 ps
                  Date.now() ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 39.61 ns
                                                                         

summary
  1 + 1
   375.26x faster than Date.now()

------------------------------------------- -------------------------------
2 + 2                        117.75 ps/iter  91.55 ps                     !
                       (61.04 ps  3.69 µs) 112.06 ps ▁▁▁▁▁▁▁▁█▁▁▁█▁▁▁▁▁▁▁▁
3 + 3                        126.97 ps/iter  91.55 ps                     !
                       (61.04 ps  4.23 µs) 122.07 ps ▁▁▁▁▁▁▁█▁▁█▁▁▁▁▁▁▄▁▁▂

                                                                         
                       2 + 2  117.75 ps
                       3 + 3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 126.97 ps
                                                                         

summary
  2 + 2
   1.08x faster than 3 + 3

other notable changes

  • support for detecting webcontainers
  • benchmark names now have 28 chars of space
  • optimized amount of ansi codes outputted in some charts

🚀 New Features

benchmark names can be highlighted

bench(...).highlight('red');
image

markdown table format

await run({ format: 'markdown' });

clk: ~3.17 GHz
cpu: Apple M2 Pro
runtime: bun 1.1.26 (arm64-darwin)

benchmark avg min p75 p99 max
1 + 1 90.69 ps/iter 61.04 ps 91.55 ps 122.07 ps 309.74 ns
Date.now() 28.70 ns/iter 26.70 ns 28.01 ns 43.35 ns 413.05 ns

option to fine tune garbage collection behavior

// runs gc before each iteration 
bench(...).gc('inner');

mitata v1 - stable release

28 Sep 18:14
Compare
Choose a tag to compare

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