Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mitata

> 数据库
Open source

benchmark tooling that loves you ❤️

2.5K stars0 likes2 views
WebsiteGitHub

About

benchmark tooling that loves you ❤️

mitata



Install

bun add mitata

npm install mitata

try mitata in browser with ai assistant at https://bolt.new/~/mitata

Recommendations

  • use dedicated hardware for running benchmarks
  • read writing good benchmarks & LLVM benchmarking tips
  • run with manual garbage collection enabled (e.g. node --expose-gc ...)
  • install optional hardware counters extension to see cpu stats like IPC (instructions per cycle)
  • make sure your runtime has high-resolution timers and other relevant options/permissions enabled

Quick Start

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

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

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

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

await run();
cpp
#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();
}

configure your experience

javascript
import { run } from 'mitata';

await run({ format: 'json' }) // output json
await run({ filter: /new Array.*/ }) // only run benchmarks that match regex filter
await run({ throw: true }); // will immediately throw instead of handling error quietly
await run({ format: { mitata: { name: 'fixed' } } }); // benchmarks name column is fixed length

// c++
auto stats = runner.run({ .colors = true, .format = "json", .filter = std::regex(".*") });

garbage collection

By default, on runtimes with exposed manual gc (like bun or node with --expose-gc), mitata runs garbage collection once after each benchmark warmup.

This behavior can be customized using gc(mode) method on benchmarks:

javascript
bench('lots of allocations', () => {
  Array.from({ length: 1024 }, () => Array.from({ length: 1024 }, () => new Array(1024)));
})
  // mode: false | 'once' (default) | 'inner'

  // once mode runs gc after warmup
  // inner mode runs gc after warmup and before each (batch-)iteration
  .gc('inner');

gc impact and memory usage

For runtimes that provide manual garbage collection or offer access to javscript vm heap usage metrics, additional row will be shown with garbage collection timings or/and estimated heap usage.

javascript
------------------------------------------- -------------------------------
new Array(512)               509.42 ns/iter 536.53 ns  ▅▃█      ▂          
                    (449.52 ns … 632.54 ns) 609.34 ns  ███   ▃▅▆█▇         
                    (  0.00  b …  24.00 kb)   1.61 kb ▆████▅▄██████▅▅▅█▅▄▂▂

Array.from(512)                1.29 µs/iter   1.30 µs  ▂▆█                 
                        (1.27 µs … 1.48 µs)   1.40 µs ▂███▇▆▃▃▂▁▁▂▁▁▁▁▁▁▁▁▁
                  gc(457.25 µs … 760.54 µs) 512.32  b (  0.00  b… 84.00 kb)

universal compatibility

Out of box mitata can detect engine/runtime it's running on and fall back to using alternative non-standard I/O functions. If your engine or runtime is missing support, open an issue or pr requesting for support.

how to use mitata with engine CLIs like d8, jsc, graaljs, spidermonkey

bash
$ xs bench.mjs
$ quickjs bench.mjs
$ d8 --expose-gc bench.mjs
$ spidermonkey -m bench.mjs
$ graaljs --js.timer-resolution=1 bench.mjs
$ /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Helpers/jsc bench.mjs
javascript
// bench.mjs

import { print } from './src/lib.mjs';
import { run, bench } from './src/main.mjs'; // git clone
import { run, bench } from './node_modules/mitata/src/main.mjs'; // npm install

print('hello world'); // works on every engine

adding arguments and parameters to your benchmarks has never been so easy

With other benchmarking libraries, often it's quite hard to easily make benchmarks that go over a range or run the same function with different arguments without writing spaghetti code, but now with mitata converting your benchmark to use arguments is just a function call away.

javascript
import { bench } from 'mitata';

bench(function* look_mom_no_spaghetti(state) {
  const len = state.get('len');
  const len2 = state.get('len2');
  yield () => new Array(len * len2);
})

.args('len', [1, 2, 3])
.range('len', 1, 1024) // 1, 8, 64, 512...
.dense_range('len', 1, 100) // 1, 2, 3 ... 99, 100
.args({ len: [1, 2, 3], len2: ['4', '5', '6'] }) // every possible combination

computed parameters

For cases where you need unique copy of value for each iteration, mitata supports creating computed parameters that do not count towards benchmark results (note: there is no guarantee of recompute time, order, or call count):

javascript
bench('deleting $keys from object', function* (state) {
  const keys = state.get('keys');

  const obj = {};
  for (let i = 0; i < keys; i++) obj[i] = i;

  yield {
    [0]() {
      return { ...obj };
    },

    bench(p0) {
      for (let i = 0; i < keys; i++) delete p0[i];
    },
  };
}).args('keys', [1, 10, 100]);

concurrency

concurrency option enables transparent concurrent execution of asynchronous benchmark, providing insights into:

  • scalability of async functions
  • potential bottlenecks in parallel code
  • performance under different levels of concurrency

(note: concurrent benchmarks may have higher variance due to scheduling, contention, event loop and async overhead)

javascript
bench('sleepAsync(1000) x $concurrency', function* () {
  // concurrency inherited from arguments
  yield async () => await sleepAsync(1000);
}).args('concurrency', [1, 5, 10]);

bench('sleepAsync(1000) x 5', function* () {
  yield {
    // concurrency is set manually
    concurrency: 5,

    async bench() {
      await sleepAsync(1000);
    },
  };
});

hardware counters

bun add @mitata/counters

npm install @mitata/counters

supported on: macos (apple silicon) | linux (amd64, aarch64)

linux:

  • /proc/sys/kernel/perf_event_paranoid has to be set to 2 or lower
  • on some vm systems pmu is disabled by hypervisor (usually when cpu core is shared across vms)

macos:

  • Apple Silicon CPU optimization guide/handbook
  • Xcode must be installed for complete cpu counters support
  • Instruments.app (CPU Counters) has to be closed during benchmarking
  • Corrupted install of Xcode/Command Line Tools can result in kernel panic (requires Xcode/Command Line Tools reinstall)

By installing @mitata/counters package you can enable collection and displaying of hardware counters for benchmarks.

…

helpful warnings

For those who love doing micro-benchmarks, mitata can automatically detect and inform you about optimization passes like dead code elimination without requiring any special engine flags.

rust
-------------------------------------- -------------------------------
1 + 1                   318.63 ps/iter 325.37 ps        ▇  █           !
                (267.92 ps … 14.28 ns) 382.81 ps ▁▁▁▁▁▁▁█▁▁█▁▁▁▁▁▁▁▁▁▁
empty function          319.36 ps/iter 325.37 ps          █ ▅          !
                (248.62 ps … 46.61 ns) 382.81 ps ▁▁▁▁▁▁▃▁▁█▁█▇▁▁▁▁▁▁▁▁

! = benchmark was likely optimized out (dead code elimination)

powerful visualizations right in your terminal

With mitata’s ascii rendering capabilities, now you can easily visualize samples in barplots, boxplots, lineplots, histograms, and get clear summaries without any additional tools or dependencies.

…

give your own code power of mitata

In case you don’t need all the fluff that comes with mitata or just need raw results, mitata exports its fundamental building blocks to allow you to easily build your own tooling and wrappers without losing any core benefits of using mitata.

cpp
#include "src/mitata.hpp"

int main() {
  auto stats = mitata::lib::fn([]() { /***/ })
}
…

accuracy down to picoseconds

By leveraging the power of javascript JIT compilation, mitata is able to generate zero-overhead measurement loops that provide picoseconds precision in timing measurements. These loops are so precise that they can even be reused to provide additional features like CPU clock frequency estimation and dead code elimination detection, all while staying inside javascript vm sandbox.

With computed parameters and garbage collection tuning, you can tap into mitata's code generation capabilities to further refine the accuracy of your benchmarks. Using computed parameters ensures that parameters computation is moved outside the benchmark, thereby preventing the javascript JIT from performing loop invariant code motion optimization.

…
same test with v8 jit compiler disabled:
…

writing good benchmarks

Creating accurate and meaningful benchmarks requires careful attention to how modern JavaScript engines optimize code. This covers essential concepts and best practices to ensure your benchmarks measure actual performance characteristics rather than optimization artifacts.

examples

  • readme gif
  • cpu cache line size
  • holey vs packed arrays

dead code elimination

JIT can detect and eliminate code that has no observable effects. To ensure your benchmark code executes as intended, you must create observable side effects.

javascript
import { do_not_optimize } from 'mitata';

bench(function* () {
  // ❌ Bad: jit can see that function has zero side-effects
  yield () => new Array(0);
  // will get optimized to:
  /*
    yield () => {};
  */

  // ✅ Good: do_not_optimize(value) emits code that causes side-effects
  yield () => do_not_optimize(new Array(0));
});

garbage collection pressure

For benchmarks involving significant memory allocations, controlling garbage collection frequency can improve results consistency.

javascript
// ❌ Bad: unpredictable gc pauses
bench(() => {
  const bigArray = new Array(1000000);
});

// ✅ Good: gc before each (batch-)iteration
bench(() => {
  const bigArray = new Array(1000000);
}).gc('inner'); // run gc before each iteration

loop invariant code motion optimization

JavaScript engines can optimize away repeated computations by hoisting them out of loops or caching results. Use computed parameters to prevent loop invariant code motion optimization.

…

License

MIT © evanwashere

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptbenchmarkbuncppdeno

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库