Add performance regression detection: indexes, timing middleware, benchmark script

Nightshift-Task: perf-regression
Nightshift-Ref: https://github.com/marcus/nightshift
This commit is contained in:
2026-03-20 02:44:57 -04:00
parent ccd0fb2155
commit 0a1e3666ef
5 changed files with 94 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
'use strict';
const SLOW_THRESHOLD_MS = 200;
function timingMiddleware(req, res, next) {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
const msg = `${req.method} ${req.path} ${res.statusCode} ${duration}ms`;
if (duration >= SLOW_THRESHOLD_MS) {
console.warn(`[SLOW] ${msg}`);
} else {
console.log(`[timing] ${msg}`);
}
});
next();
}
module.exports = timingMiddleware;