Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-bench

@5f83e6c
Run it yourself

Node.js now has a built-in benchmark runner, node:bench. Use it whenever writing or running a JavaScript performance benchmark instead of a hand-written timing loop: "which is faster", measuring how fast code is, comparing two implementations, check for a performance regression, or when reaching for benchmark.js, tinybench or mitata. Covers bench, suite/describe, hooks, BenchContext start/end/record, doNotOptimize, createRunner/run, reporters, and the --experimental-bench and --bench* flags. Node.js 26.9+ only (not on v24).

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-bench

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈135 tokens for metadata: the name and description. ≈935 when used: this file. ≈3.3k more on demand in 4 files.

Description uses 6.8% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈542 characters, or 6.8%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

node:bench

Feature Versions Stability Flag
node:bench (bench, suite, describe, hooks, createRunner, run, runFile), node:bench/reporters v26.9.0 (not on v24) 1.0 Early development --experimental-bench
--bench and --bench-* flags (except --bench-gc) v26.9.0 1 Experimental --experimental-bench
doNotOptimize, --bench-gc, the gc option, end() defaulting to 1 op, the bench:environment record added: REPLACEME (main only; absent in v26.13.0) 1.0 --experimental-bench

Experimental API. Before relying on these details, run the node-experimental-check skill's probe (or node --version plus a feature-detect one-liner) and check the docs for the installed version: https://nodejs.org/docs/<version>/api/<module>.html. If the installed version disagrees with this skill, the installed version wins.

A benchmark file

// parse.bench.mjs: declare only, never call run() (the CLI rejects it)
import { bench, suite } from 'node:bench';
suite('JSON', () => {
  const input = JSON.stringify({ a: [1, 2, 3] });
  bench('parse', { samples: 30, warmup: 10 }, (b) => {
    const ops = 10_000; let n = 0;
    b.start();
    for (let i = 0; i < ops; i++) n += JSON.parse(input).a.length;
    b.end(ops);                       // always pass operations (required on v26.13)
    if (n !== 3 * ops) throw new Error('wrong result'); // keep the work observable
  });
});
node --experimental-bench --bench 'bench/**/*.bench.mjs'   # one child process per file
node --experimental-bench --bench --bench-reporter=json --bench-samples=50 x.bench.mjs > out.ndjson

Results in code

import { createRunner } from 'node:bench';
const r = createRunner();             // runs only on r.run(), once
r.bench('x', { samples: 20 }, (b) => { b.start(); work(); b.end(1); });
for await (const { type, data } of r.run())
  if (type === 'bench:complete' && !data.error) use(data.samples, data.summary);

Each sample is { operations, duration_ns: bigint, rate /* ops/s */ }. summary.mean is the mean of per-sample rates, not pooled throughput. To ask "is B faster than A", record integer ns or ps per op into a Histogram and use welchTest/mannWhitneyTest. See the node-histogram-stats skill.

Pitfalls

  • Each warmup and each sample calls fn once with a new context, and fn must call start()+end() or record() exactly once. beforeEach runs once per benchmark, not per sample.
  • A loop whose result is unused can be eliminated. The spec reporter flags ≥ 1 op/ns as implausible. Validate an aggregate, or use doNotOptimize(v) on main.
  • A failure in a module-level run sets process.exitCode = 1. createRunner() runs don't.
  • gc: 'once' | 'sample' needs --expose-gc. --bench-gc adds it to children automatically, except with --bench-isolation=none. On v26.13 gc is silently ignored.
  • --bench can't be combined with --test, --watch, --eval or --check.

Don't

  • Don't hand-roll Date.now()/performance.now() loops: they have no warmup or per-sample stats.
  • Don't add benchmark.js, tinybench, mitata or cronometro when Node ≥ 26.9 is available. Use node:bench.
  • Don't treat a confidence interval as pass/fail. Keep the raw samples.

Reference

  • rules/api.md — read for every option, BenchContext method, hook, and event/result field.
  • rules/cli.md — read for flags, isolation modes, reporters (spec/json/custom), and runFile.
  • rules/measurement.md — read for warmup, GC modes, dead-code elimination, variable batches, and comparing runs.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides comprehensive documentation and examples for the Node.js built-in benchmark runner (node:bench). It includes API references, CLI usage guides, and example scripts for running and comparing benchmarks. All operations use standard Node.js built-in modules and follow safe development practices.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-bench