`BENCHMARKS.md` answered "how does this compare to fastify" and nothing answered "did the last two months cost anything". Those are different questions and the second one is the one a release has to pass, so it needed its own tool rather than a second reading of the first one's table. `npm run bench:compare` runs two worktrees of this repository against each other on one box in one sitting, alternating which side goes first each round so drift lands on both rather than on whichever ran second. It shares one `node_modules` and one byte-identical server file, which holds everything except `src/` constant — and is only sound while `package.json` has not moved between the revisions, which the header says out loud. Three things it refuses to do quietly, each of which it did once before being taught not to: - A run whose connections all errored reports 0 req/s, and a median absorbs that without complaint. Non-2xx, errors and timeouts now fail the case, and so does a zero. Not on the warmup, which exists to absorb exactly the cold-start noise a fresh server produces. - A range-overlap check flags a row as directional, and its own documentation says to treat that as "measure it again", never as a result. Three samples of two overlapping distributions separate by chance often enough to have produced a regression report that five rounds then erased. - `cors.origins` invocations are counted rather than timed. The benchmark's predicate is a `Set` lookup, so calls saved are invisible in req/s — but the option takes a function so it can be a lookup, and there the same saving is a network round trip. **The runtime servers finally run.** `bench/servers/green-tea-deno.ts` and `-bun.ts` were written in July and referenced by nothing — not the runner, not a script, not CI. The runner only knew how to launch Node, so both sat there looking like coverage the table did not have. Launchers are per runtime now and they get their own section, kept out of the cross-framework tables because a green-tea-on-Bun row beside fastify-on-Node reads as a comparison nobody made. `green-tea-node.ts` is new and loads `dist/` like its Deno and Bun counterparts. The runtimes table exists to vary the runtime, and a Node row reading `src/` through tsx would have varied the load form at the same time. A route-table-width dimension, because every matcher cost scales with how many candidates a request walks past and the tables here use six routes. Three separate matcher findings measured as noise before this existed, which said nothing about them and everything about the instrument. Finally, `run.ts` preserves whatever sits below a marker instead of overwriting the file whole. The tables answer what is true today; the notes below them carry which release moved a number and what the move bought, and regenerating used to delete that silently. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
122 lines
4.1 KiB
TypeScript
122 lines
4.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { aggregate } from '../bench/stats';
|
|
import { renderMarkdown } from '../bench/render';
|
|
|
|
describe('aggregate', () => {
|
|
it('median, stddev, cv, min/max over run req/s', () => {
|
|
const a = aggregate([100, 110, 120, 130, 140]);
|
|
expect(a.median).toBe(120);
|
|
expect(a.min).toBe(100);
|
|
expect(a.max).toBe(140);
|
|
expect(a.stddev).toBeGreaterThan(0);
|
|
expect(a.cv).toBeCloseTo(a.stddev / a.mean, 6);
|
|
});
|
|
});
|
|
|
|
describe('renderMarkdown', () => {
|
|
const data = {
|
|
env: {
|
|
date: '2026-07-06',
|
|
commit: 'abc123',
|
|
node: 'v18.19.0',
|
|
os: 'darwin',
|
|
cpu: 'M1 (8 cores)',
|
|
ram: '16 GB',
|
|
pinned: false,
|
|
},
|
|
config: { conns: 100, duration: 10, runs: 5, warmup: 1, pipelining: 1 },
|
|
scenarios: [
|
|
{
|
|
title: 'JSON hello (overhead)',
|
|
name: 'hello',
|
|
approximation: false,
|
|
rows: [
|
|
{
|
|
framework: 'fastify',
|
|
reqSec: { median: 50000, min: 49000, max: 51000, stddev: 700, cv: 0.014 },
|
|
p50: 1.5,
|
|
p99: 4,
|
|
p999: 9,
|
|
},
|
|
{
|
|
framework: 'green-tea',
|
|
reqSec: { median: 42000, min: 41000, max: 43000, stddev: 600, cv: 0.014 },
|
|
p50: 1.9,
|
|
p99: 5,
|
|
p999: 11,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
stepScaling: [
|
|
{ path: '/steps/0', steps: 0, reqSec: 45000 },
|
|
{ path: '/steps/3', steps: 3, reqSec: 40000 },
|
|
],
|
|
secureCost: [
|
|
{ label: 'security:false (parity)', reqSec: 45000 },
|
|
{ label: 'security:true (default)', reqSec: 43000 },
|
|
],
|
|
};
|
|
it('renders env header, a per-scenario table with a row per framework, and the micro-bench sections', () => {
|
|
const md = renderMarkdown(data as any);
|
|
expect(md).toContain('# green-tea Benchmarks');
|
|
expect(md).toContain('abc123'); // commit
|
|
expect(md).toContain('single-box'); // contention caveat
|
|
expect(md).toContain('JSON hello (overhead)');
|
|
expect(md).toContain('fastify');
|
|
expect(md).toContain('green-tea');
|
|
expect(md).toMatch(/req\/s/i);
|
|
expect(md).toContain('p99');
|
|
expect(md).toContain('Step-scaling');
|
|
expect(md).toContain('secure-by-default');
|
|
expect(md).toContain('approximation'); // methodology mentions the pipeline approximation
|
|
});
|
|
it('sorts each scenario rows by median req/s descending', () => {
|
|
const md = renderMarkdown(data as any);
|
|
expect(md.indexOf('fastify')).toBeLessThan(md.indexOf('green-tea')); // fastify (50k) before green-tea (42k)
|
|
});
|
|
});
|
|
|
|
describe('renderMarkdown runtime matrix', () => {
|
|
const base = {
|
|
env: { date: '2026-09-01', commit: 'abc1234', node: 'v22', os: 'darwin', cpu: 'M4', ram: '69 GB', pinned: false },
|
|
config: { conns: 100, duration: 10, runs: 5, warmup: 1, pipelining: 1 },
|
|
scenarios: [],
|
|
stepScaling: [],
|
|
secureCost: [],
|
|
};
|
|
|
|
it('renders one column per runtime and one row per scenario', () => {
|
|
const md = renderMarkdown({
|
|
...base,
|
|
runtimes: [
|
|
{ runtime: 'node', scenario: 'JSON hello', reqSec: 90_000 },
|
|
{ runtime: 'bun', scenario: 'JSON hello', reqSec: 120_000 },
|
|
],
|
|
} as never);
|
|
|
|
expect(md).toContain('## green-tea across runtimes');
|
|
expect(md).toContain('| Scenario | node | bun |');
|
|
expect(md).toContain('| JSON hello | 90,000 | 120,000 |');
|
|
});
|
|
|
|
it('marks a runtime that produced no number rather than printing a zero', () => {
|
|
// A skipped runtime must not read as "it ran and scored nothing".
|
|
const md = renderMarkdown({
|
|
...base,
|
|
runtimes: [
|
|
{ runtime: 'node', scenario: 'JSON hello', reqSec: 90_000 },
|
|
{ runtime: 'deno', scenario: 'Route param', reqSec: 80_000 },
|
|
],
|
|
} as never);
|
|
|
|
expect(md).toContain('| JSON hello | 90,000 | — |');
|
|
expect(md).toContain('| Route param | — | 80,000 |');
|
|
});
|
|
|
|
it('omits the section entirely when no runtime was measured', () => {
|
|
expect(renderMarkdown({ ...base, runtimes: [] } as never)).not.toContain('across runtimes');
|
|
expect(renderMarkdown(base as never)).not.toContain('across runtimes');
|
|
});
|
|
});
|