Performance regression tests
A performance regression test compares measured behavior against an agreed baseline under a repeatable workload. It must first establish that both versions produce the right result. Keep input size, runtime, warmup, sample count, concurrency, and environment fixed. Record raw samples and summarize with a median or appropriate percentiles; do not hide outliers. Compare a baseline and a candidate one change at a time. Use an absolute budget and a relative change threshold chosen from repeatability measurements, not arbitrary numbers on shared CI. Timing is noisy; use repeated runs and investigate reproducible failures. The fixture below validates actual timings and results without declaring a winner. Its second example is a synthetic release-policy decision, not a measured benchmark. Never claim a speedup merely because one measurement was lower; measure construction, memory and errors when they affect the workload. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/perf_hooks.html.
Formal Syntax & Structure
performance.now()Working Example
import {performance} from 'node:perf_hooks';import assert from 'node:assert/strict';const ids=Array.from({length:1000},(_,i)=>i), set=new Set(ids);const queries=[0,500,999,-1];for(const lookup of [x=>ids.includes(x),x=>set.has(x)]){ const run=()=>{let hits=0;for(let i=0;i<1000;i++)for(const q of queries)hits+=Number(lookup(q));return hits;}; for(let i=0;i<3;i++)assert.equal(run(),3000); const samples=[];for(let i=0;i<5;i++){const t=performance.now();assert.equal(run(),3000);samples.push(performance.now()-t);} assert.ok(samples.every(x=>Number.isFinite(x)&&x>=0)); console.log('5 samples; 3000 hits');}