Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mitata

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mitata

cross-runtime benchmarking lib

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
increased by26.32%
Maintainers
1
Weekly downloads
 
Created
Source

mitata

cross-runtime benchmarking lib

Install

bun add mitata

npm install mitata

Examples

import { run, bench, group, baseline } from 'mitata';

// deno
// import { ... } from 'https://esm.sh/mitata';

// d8/jsc
// import { ... } from '<path to mitata>/src/cli.mjs';

bench('noop', () => {});
bench('noop2', () => {});

group('group', () => {
  baseline('baseline', () => {});
  bench('Date.now()', () => Date.now());
  bench('performance.now()', () => performance.now());
});

group({ name: 'group2', summary: false }, () => {
  bench('new Array(0)', () => new Array(0));
  bench('new Array(1024)', () => new Array(1024));
});

await run({
  avg: true, // enable/disable avg column (default: true)
  json: false, // enable/disable json output (default: false)
  colors: true, // enable/disable colors (default: true)
  min_max: true, // enable/disable min/max column (default: true)
  collect: false, // enable/disable collecting returned values into an array during the benchmark (default: false)
  percentiles: false, // enable/disable percentiles column (default: true)
});

output:

terminal screenshot (click to view)

preview.png

cpu: Apple M1
runtime: bun 0.0.83 (arm64-darwin)

benchmark              time (avg)             (min … max)
---------------------------------------------------------
noop               323.34 ps/iter    (304.1 ps … 8.64 ns)
noop2              387.15 ps/iter   (304.1 ps … 16.79 ns)

• group
---------------------------------------------------------
baseline           782.71 ps/iter    (304.1 ps … 6.34 ns)
Date.now()          31.04 ns/iter    (30.9 ns … 34.59 ns)
performance.now()   92.71 ns/iter  (91.72 ns … 101.45 ns)

summary for group
  baseline
   39.66x faster than Date.now()
   118.45x faster than performance.now()

• group2
---------------------------------------------------------
new Array(0)         7.47 ns/iter   (6.46 ns … 269.07 ns)
new Array(1024)    286.39 ns/iter  (241.37 ns … 560.7 ns)

JIT bias

If you run benchmarks like this, you might notice that they get slower (only few nanoseconds) after the first few runs.

bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});
bench('noop', () => {});

I call this behavior "JIT bias". In simple words, v8 and JSC JIT expect us to pass the same function, so they optimize for it, but we break that promise and get deoptimized.

License

MIT © Evan

FAQs

Package last updated on 09 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc