A benchmarking framework for JavaScript and TypeScript that makes it easy to write, run, analyse, and compare performance benchmarks.
Developers write benchmark files using the Benched library, then execute them using the benched CLI. During execution, Benched displays a live terminal interface showing benchmark progress, statistics, and results. After completion, results can be compared, exported, or used in CI pipelines to detect performance regressions.
pnpm add -D benched-jsCreate a benchmark file:
// array.bench.ts
import { suite, bench } from "benched-js";
suite("Array Operations", () => {
bench("Array.push()", () => {
const arr: number[] = [];
for (let i = 0; i < 10000; i++) {
arr.push(i);
}
});
bench("Array spread", () => {
let arr: number[] = [];
for (let i = 0; i < 10000; i++) {
arr = [...arr, i];
}
});
});Run it:
benched run array.bench.tsbenched run [files...]
benched run **/*.bench.ts
benched run --tag parser
benched run array.bench.ts --export json
benched run array.bench.ts --export csv
benched run --workers 4 --no-ui
benched run --verbose| Flag | Description |
|---|---|
--tag <tag> |
Run only benchmarks with the given tag |
--export <format> |
Export results as json or csv |
--workers <n> |
Number of worker threads for parallel execution |
--no-ui |
Disable live terminal UI (useful in CI) |
--verbose |
Show min, max, and ops/s statistics |
benched compare baseline.json current.jsonExample output:
JSON.parse()
Before 1.82ms
After 1.47ms
19.2% faster
Create a benched.config.ts file in your project root:
export default {
workers: 4,
parallel: true,
samples: 50,
warmup: 32,
timeout: 5000,
export: {
formats: ["json"],
includeEnvironment: true,
includeSamples: false,
outputDir: ".",
},
ui: {
theme: "default",
liveUpdates: true,
},
};See benched.config.example.ts for a full example.
Define a group of related benchmarks.
Define a single benchmark.
bench("Hash", fn, {
warmup: 500,
samples: 100,
iterations: 1,
timeout: 5000,
tags: ["parser", "json"],
});bench("Database query", async () => {
await db.query("SELECT 1");
});Each benchmark reports:
- Mean, median, min, max
- Standard deviation and variance
- Operations per second
- Sample count
Warm-up iterations run before sampling to reduce JIT compilation effects. Configure per benchmark or globally.
Run independent benchmarks concurrently using worker threads:
benched run --workers 4Enable parallel: true in your config to use workers by default.
bench("Parser", fn, { tags: ["parser", "json"] });benched run --tag parserExport results to JSON or CSV with optional environment metadata:
benched run array.bench.ts --export json
benched run array.bench.ts --export csvJSON exports include runtime, OS, CPU, memory, timestamp, and optional git commit hash.
Benched automatically captures:
- Node/Bun/Deno version
- Operating system and architecture
- CPU model
- Total memory
- Timestamp
- Git commit (when available)
- name: Run benchmarks
run: pnpm benched run --no-ui --export json
- name: Compare against baseline
run: pnpm benched compare baseline.json benched-results-*.jsonUse --no-ui in CI environments that do not support interactive terminal output.
pnpm install
pnpm build
pnpm test
pnpm typecheckRun the example benchmark:
pnpm build
node dist/cli/index.js run examples/array.bench.tsMIT © Ethan Davies