test(benchmarks): add tolerance to response packet regression test

Add 5% tolerance for timing noise to prevent flaky failures from
nanosecond-level benchmark variations
This commit is contained in:
Jeremie Fraeys 2026-02-18 12:45:40 -05:00
parent 38c09c92bb
commit 6c83bda608
No known key found for this signature in database

View file

@ -20,8 +20,10 @@ func TestResponsePacketSerializationRegression(t *testing.T) {
benchmarkLegacySerializePacket(b, variant.packet)
})
if current.NsPerOp() > legacy.NsPerOp() {
t.Fatalf("current serialize slower than legacy: current=%dns legacy=%dns", current.NsPerOp(), legacy.NsPerOp())
// Allow 5% tolerance for timing noise - single nanosecond differences are within measurement error
tolerance := int64(float64(legacy.NsPerOp()) * 0.05)
if current.NsPerOp() > legacy.NsPerOp()+tolerance {
t.Fatalf("current serialize slower than legacy: current=%dns legacy=%dns (tolerance=%dns)", current.NsPerOp(), legacy.NsPerOp(), tolerance)
}
if ceil, ok := packetAllocCeil[variant.name]; ok && current.AllocsPerOp() > ceil {