High-performance benchmarking utilities for Node.js and browser environments, powered by Funish.
- 🚀 Simple and intuitive API
- 📊 Comprehensive statistical analysis
- ⏱️ High-resolution timing
- 🔄 Multiple time units support (s, ms, µs, ns)
- 🌐 Works in Node.js and browsers
- 📈 Detailed performance metrics
- 📦 Zero dependencies
- 🌟 Full TypeScript support
# npm
$ npm install @funish/bench
# yarn
$ yarn add @funish/bench
# pnpm
$ pnpm add @funish/benchimport { Bench } from "@funish/bench";
const bench = new Bench({
times: 1000, // Number of iterations
unit: "ms", // Time unit (s, ms, µs, ns)
});
// Add tasks to benchmark
bench.add("Array.push", () => {
const arr = [];
arr.push(1);
});
bench.add("Array literal", () => {
const arr = [1];
});
// Print results
bench.print();new Bench()
.add("Task 1", () => {
/* ... */
})
.add("Task 2", () => {
/* ... */
})
.print();const bench = new Bench();
bench.add("test", () => {
/* ... */
});
const results = bench.getResults();
// Process results as needednew Bench(options?: BenchOptions)times(number, default: 1000): Number of iterations for each taskunit("s" | "ms" | "µs" | "ns", default: "ns"): Time unit for results
Adds a task to benchmark.
name: Task identifierfn: Function to benchmark- Returns: The Bench instance for chaining
Prints results to console in a table format.
Returns a copy of the benchmark results.
Each result contains:
- Task name
- Total time
- Average time
- Fastest time
- Slowest time
- Median time
- Standard deviation
Example output:
┌─────────┬────────────┬─────────────┬─────────────┬─────────────┬─────────────┬────────────────────┐
│ Task │ Total (ms) │ Average (ms)│ Fastest (ms)│ Slowest (ms)│ Median (ms) │ Standard deviation │
├─────────┼────────────┼─────────────┼─────────────┼─────────────┼─────────────┼────────────────────┤
│ Task 1 │ 100.000 │ 0.100 │ 0.080 │ 0.150 │ 0.095 │ 0.015 │
└─────────┴────────────┴─────────────┴─────────────┴─────────────┴─────────────┴────────────────────┘
Please read our Contributing Guide before submitting a Pull Request to the project.