Skip to content

Conversation

@nigrosimone
Copy link
Contributor

@nigrosimone nigrosimone commented Dec 13, 2025

This PR introduces a new CLI command bench:cmp that allows benchmarking and comparing the performance of two git branches.

The goal is to make performance regressions or improvements immediately visible while developing or reviewing PRs.

Usage

Compare the current branch against the default branch (main):

npm run bench:cmp -- current

Benchmark my-branch against other-branch:

npm run bench:cmp -- my-branch other-branch 

If bench:cmp is executed without parameters, an interactive mode is enabled. The CLI will prompt to select:

  • the feature branch
  • the branch to compare against
npm run bench:cmp                             

> ultimate-express@2.0.13 bench:cmp
> node ./bench/bench-cmp-branch.js

Select the branch you want to compare (feature branch):
(x) FIX-CONTENT-TYPE-2
( ) array-jsonp
( ) async-error-handling-array
( ) bench-both-4-4
...

What it does

  • Checks out each branch sequentially
  • Runs the existing npm run bench script
  • Parses benchmark output
  • Compares results scenario-by-scenario
  • Prints percentage differences
  • Highlights relevant changes:
    • Green → improvement greater than +5%
    • Red → regression worse than -5%
    • Neutral values are shown without color

At the end, it automatically switches back to the original branch.

Example output

npm run bench:cmp -- my-branch other-branch

Node v22.13.0 on win32/x64
CPU Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 cores) RAM 15.6 GB

> ultimate-express@2.0.13 bench:cmp
> node ./bench/bench-cmp-branch.js my-branch other-branch

Checking out "my-branch"
Execute "npm run bench"

> ultimate-express@2.0.13 bench
> node --expose-gc ./bench/bench.js

long string...... x 3583 req/sec

Checking out "other-branch"
Execute "npm run bench"

> ultimate-express@2.0.13 bench
> node --expose-gc ./bench/bench.js

long string...... x 3360 req/sec


long string.......+6.64%

the console show the improvements with colors

Bench scenarios

The long string benchmark scenarios are currently included is defined in https://github.com/nigrosimone/ultimate-express/blob/pr-vs-master/bench/bench.js#L9 and https://github.com/nigrosimone/ultimate-express/blob/pr-vs-master/bench/server.js#L17 (we can add more)

const benchmarks = [
  {
    name: "long string",
    path: "/long-string",
  },
];
const LONG_STRING = "hello".repeat(10_000);

app.get("/long-string", (req, res) => {
  res.send(LONG_STRING);
});

Why

This makes performance changes measurable and repeatable during development, instead of relying on intuition or ad-hoc testing. This also can help for understand if this my other PR #267 is good

It could be useful to add bench:cmp as a GitHub Action on PRs.

@nigrosimone nigrosimone changed the title feat: developing tool for benchmark PR vs MASTER feat: add bench:cmp command to compare benchmark results between branches Dec 13, 2025
@nigrosimone nigrosimone marked this pull request as ready for review December 13, 2025 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant