Skip to content

manekinekko/rich-bench-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rich-Bench for Node.js

A Tiny Benchmarking Tool for Node.js (this is a port of the original python tool rich-bench by Anthony Shaw)

πŸš€ Overview

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.

πŸ“¦ Installation

1️⃣ Install Locally for Development

git clone https://github.com/manekinekko/rich-bench-node.git
cd rich-bench
npm install
npm link  # Enable CLI usage globally

πŸ›  Usage

Basic Benchmark Execution

rich-bench benchmarks/

Run a Specific Benchmark

rich-bench benchmarks/ --benchmark encoding_format

Show Percentage Instead of Multipliers

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%) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Repeat Benchmark Execution

rich-bench benchmarks/ --repeat 100

Run benchmarks N times

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. --repeatand --times will be used.

πŸ“Š Example Output

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‘ Writing a Benchmark

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/

Features

βœ” Compares two functions side by side
βœ” Displays min, max, and mean execution times
βœ” Highlights performance gains with colors

Credits

Shoutout to Anthony Shaw for creating the original rich-bench tool in Python.

About

A Tiny Benchmarking Tool for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published