Debian Codegraph @

tests/benchmarks/__init__.py

raw
1 """CodSpeed benchmarks.
2
3 These are only collected when ``pytest-codspeed`` is installed, which is the
4 case in the dedicated ``benchmark`` tox environment (see ``tox.ini``). In every
5 other environment they are skipped, so the regular test runs are unaffected.
6 """
7
8 import pytest
9
10 pytest.importorskip("pytest_codspeed", reason="Benchmark tests require pytest-codspeed")
11
12 # Relative date strings in the form the freshness parser actually receives them:
13 # the locale translates the input first, which turns plural units singular
14 # ("2 hours, 50 minutes ago" -> "2 hour 50 minute ago"). PATTERN only matches
15 # singular units, so benchmarking the untranslated strings would measure a failed
16 # scan instead of the real workload.
17 #
18 # Each benchmark runs the whole list rather than a single string: CodSpeed's
19 # simulation mode measures one call, and a lone match on a short string is too
20 # small a unit of work to be meaningful.
21 TRANSLATED_RELATIVE_STRINGS = [
22 "1 minute ago",
23 "2 hour 50 minute ago",
24 "3 day ago",
25 "in 2 week",
26 "10.5 year ago",
27 "1 day 2 hour 3 minute 4 second ago",
28 ]
29
30 # A long run of digits: the input shape that made the relative-date regexes
31 # backtrack superlinearly before #1335. Deliberately pathological rather than
32 # realistic -- it is what turns a reintroduced regression into an unmissable
33 # signal.
34 #
35 # The length is chosen so that a regressed run still *finishes and reports*:
36 # with the old greedy quantifiers this takes ~380ms against ~0.7ms for the
37 # possessive ones, a ~500x jump that no threshold can miss, while remaining a
38 # handful of seconds under CodSpeed's instrumentation. The 3200 digits of the
39 # original #1335 repro would instead need ~20 minutes per benchmark once
40 # regressed, so the job would time out without ever reporting.
41 LONG_DIGIT_RUN = "9" * 800