A Tiny Benchmarking Tool for Node.js (this is a port of the original python tool rich-bench by Anthony Shaw)
rich-bench
is a simple CLI tool that benchmarks JavaScript functions and provides a richly formatted performance comparison.
It measures execution time, computes performance gains, and generates insightful statistics.
git clone https://github.com/manekinekko/rich-bench-node.git
cd rich-bench
npm install
npm link # Enable CLI usage globally
rich-bench benchmarks/
rich-bench benchmarks/ --benchmark encoding_format
rich-bench benchmarks/ --percentage
This will show the performance gains as percentages instead of multipliers.
ββββββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββββββ¬βββββββββββββββββββββ
β Benchmark β Min (ms) β Max (ms) β Mean (ms) β Min (+) β Max (+) β Mean (+) β
βββββββββ-ββββΌβββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββββΌββββββββββββββββββββββΌβββββββββββββββββββββ€
β #1 β 73.376 β 19666.000 β 9844.744 β 44.430 (39.4%) β 8351.000 (57.5%) β 4213.139 (57.2%) β
ββββββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββββββ΄βββββββββββββββββββββ
rich-bench benchmarks/ --repeat 100
rich-bench benchmarks/ --times 100
Note
If the benchmarked functions returns a value, it will be used as the benchmark value and the function will be called 1 time, but still repeated --repeat
times.
If the benchmarked functions does not return a value, the execution time will be used as the benchmark value. --repeat
and --times
will be used.
βββββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββββ¬ββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββ
β Benchmark β Min (ms) β Max (ms) β Mean (ms) β Min (+) β Max (+) β Mean (+) β
βββββββββββββΌβββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββ€
β #1 β 62.825 β 19651.000 β 9861.410 β 51.549 (1.2x) β 8351.000 (2.4x) β 4217.198 (2.3x) β
βββββββββββββΌβββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββ€
β #2 β 47.765 β 19633.000 β 9852.893 β 60.384 (0.8x) β 19611.000 (1.0x) β 9841.065 (1.0x) β
βββββββββββββΌβββββββββββΌββββββββββββΌββββββββββββΌββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββ€
β #3 β 44.447 β 8351.000 β 4214.801 β 45.261 (1.0x) β 19641.000 (0.4x) β 9849.066 (0.4x) β
βββββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββββ΄ββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββ
Create a bench_*.js
file inside benchmarks/
and export an array of benchmark functions:
async function encoding_format_float(inputSize) {
const emb = await openai.embeddings.create({
model: "text-embedding-ada-002",
input: generateRandomString(inputSize),
encoding_format: "float"
});
return new Blob([emb.data[0].embedding]).size; // return bytes as the benchmark
}
async function encoding_format_base64(inputSize) {
const emb = await openai.embeddings.create({
model: "text-embedding-ada-002",
input: generateRandomString(inputSize),
encoding_format: "base64"
});
return new Blob([emb.data[0].embedding]).size; // return bytes as the benchmark
}
module.exports.__benchmarks__ = [
[
encoding_format_float,
encoding_format_base64,
"bench #1"
]
];
Then run:
npx rich-bench benchmarks/
β Compares two functions side by side
β Displays min, max, and mean execution times
β Highlights performance gains with colors
Shoutout to Anthony Shaw for creating the original rich-bench tool in Python.