mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-114911: Add CPUStopwatch test helper (GH-114912)
A few of our tests measure the time of CPU-bound operation, mainly to avoid quadratic or worse behaviour. Add a helper to ignore GC and time spent in other processes.
This commit is contained in:
parent
3b63d0769f
commit
7acf1fb5a7
3 changed files with 75 additions and 42 deletions
|
@ -1,7 +1,7 @@
|
|||
from test.support import (gc_collect, bigmemtest, _2G,
|
||||
cpython_only, captured_stdout,
|
||||
check_disallow_instantiation, is_emscripten, is_wasi,
|
||||
warnings_helper, SHORT_TIMEOUT)
|
||||
warnings_helper, SHORT_TIMEOUT, CPUStopwatch)
|
||||
import locale
|
||||
import re
|
||||
import string
|
||||
|
@ -2284,17 +2284,16 @@ class ReTests(unittest.TestCase):
|
|||
|
||||
def test_search_anchor_at_beginning(self):
|
||||
s = 'x'*10**7
|
||||
start = time.perf_counter()
|
||||
for p in r'\Ay', r'^y':
|
||||
self.assertIsNone(re.search(p, s))
|
||||
self.assertEqual(re.split(p, s), [s])
|
||||
self.assertEqual(re.findall(p, s), [])
|
||||
self.assertEqual(list(re.finditer(p, s)), [])
|
||||
self.assertEqual(re.sub(p, '', s), s)
|
||||
t = time.perf_counter() - start
|
||||
with CPUStopwatch() as stopwatch:
|
||||
for p in r'\Ay', r'^y':
|
||||
self.assertIsNone(re.search(p, s))
|
||||
self.assertEqual(re.split(p, s), [s])
|
||||
self.assertEqual(re.findall(p, s), [])
|
||||
self.assertEqual(list(re.finditer(p, s)), [])
|
||||
self.assertEqual(re.sub(p, '', s), s)
|
||||
# Without optimization it takes 1 second on my computer.
|
||||
# With optimization -- 0.0003 seconds.
|
||||
self.assertLess(t, 0.1)
|
||||
self.assertLess(stopwatch.seconds, 0.1)
|
||||
|
||||
def test_possessive_quantifiers(self):
|
||||
"""Test Possessive Quantifiers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue