Most of the cost tests in a Rust side project of mine, which rewrites HTML with scraper (and so html5ever underneath), follow one recipe, and a review of a planned test showed me an input where that recipe can't fail, so let's go through why, and what we changed in the inputs to fix it. It's a small thing about html5ever, but it applies to any test that measures your code against a library's time on the same input.
The recipe
A lot of that code walks an HTML tree and moves nodes around, and each walk has to stay linear in the size of the document, because a pass that is quadratic in it is fine on a small test file and very slow on a large one. So for each such pass there is a test that builds a large input, times the pass, and fails if it took too long.
"Too long" is not a fixed number of seconds.…