From 8bd8cac9ef1d24899aba952b178602da56cede3d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 11:06:29 -1000 Subject: Time the other filters at two lengths as well The avatar checks held a 40000 byte address to half a second, twenty times tighter than the readme budget that already failed on a slow host, and in stub mode nearly all of that time went on the fake digest. Link-commits and link-trailers had no check on a long input at all. The readme checks' method moves into the harness so all four share it. A single timing of each length let a busy host that took the CPU away during the longer one make a linear pass look quadratic. The lengths now take turns and the fastest timing of each counts, since a busy host can slow one timing but rarely all five. A ratio under six ends the turns at once, so only one near the bound of ten waits for all five. --- tests/extensions/harness.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/extensions/harness.lua') diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index 5084ab4..188d90f 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -301,6 +301,39 @@ function harness.excludes(name, haystack, needle) end end +-- Checks that a text four times as long costs about four times as much to +-- run, as a linear pass does, where a quadratic one costs sixteen times as +-- much. Timing one length against the other cancels out how fast the host +-- is. Each timing repeats the run for at least 50 ms, and the two lengths +-- take turns, keeping the fastest timing of each. A busy host can charge +-- the process for time its CPU was taken away, which slows a timing but +-- never speeds one up. A ratio under six is plainly linear and ends the +-- turns, so only one near the bound takes all five before it can fail. +-- Returns what the longer run gave back. +function harness.stays_linear(name, run, make, length) + local texts = { make(length), make(4 * length) } + local fastest = { math.huge, math.huge } + local out + for _ = 1, 5 do + for i = 1, 2 do + local runs, started = 0, os.clock() + repeat + out = run(texts[i]) + runs = runs + 1 + until os.clock() - started >= 0.05 + fastest[i] = math.min(fastest[i], (os.clock() - started) / runs) + end + if fastest[2] < 6 * fastest[1] then + break + end + end + local short, long = fastest[1], fastest[2] + harness.check(name, long < 10 * short, + string.format("%.4f s at length %d, then %.4f s at four times that", + short, length, long)) + return out +end + -- A run that made no check proves nothing, so it fails as well. function harness.finish() if failures > 0 then -- cgit 2.12.1