test: add fight loop throughput benchmark (>500 fights/sec)

Benchmarks the scoring pipeline (challenge → response → score → elo → tier)
without I/O. Currently achieves ~8500 fights/sec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 09:25:29 +00:00
co-authored by Claude Opus 4.6
parent 2f313813ee
commit 64273cf145
+41
View File
@@ -504,4 +504,45 @@ describe('fight lifecycle', () => {
.toBeLessThanOrEqual(expectedAWinMax)
}
})
it('fight loop throughput: >500 fights/second (no I/O)', () => {
const fights = 5000
const start = performance.now()
for (let f = 0; f < fights; f++) {
const eloA = 1000 + (f % 10) * 100
const eloB = 1000 + ((f * 3) % 10) * 100
const botA = { id: 'perf-a', name: 'PerfA' }
const botB = { id: 'perf-b', name: 'PerfB' }
const usedTypes = new Set<string>()
let comboA = 0
let comboB = 0
const rounds = 7 + (f % 4)
for (let r = 0; r < rounds; r++) {
const challenge = pickChallenge(usedTypes, null, undefined, r + 1)
usedTypes.add(challenge.type)
const respA = mockResponse(challenge, 'confident', eloA)
const respB = mockResponse(challenge, 'clueless', eloB)
const result = scoreRound(
challenge, botA, botB,
{ answer: respA.answer, timeMs: respA.timeMs, timedOut: respA.timedOut, error: respA.error },
{ answer: respB.answer, timeMs: respB.timeMs, timedOut: respB.timedOut, error: respB.error },
null, comboA, comboB,
)
if (result.winnerId === botA.id) { comboA++; comboB = 0 }
else if (result.winnerId === botB.id) { comboB++; comboA = 0 }
}
// Elo + tier calculation
calculateElo(eloA, eloB)
calculateTier(eloA, f % 50, f % 20)
}
const elapsed = performance.now() - start
const fightsPerSec = Math.round(fights / (elapsed / 1000))
// Must process >500 fights/sec (scoring pipeline only, no I/O)
expect(fightsPerSec).toBeGreaterThan(500)
})
})