ยปCore Development>Code coverage>Lib/test/reperf.py

Python code coverage for Lib/test/reperf.py

#countcontent
1n/aimport re
2n/aimport time
3n/a
4n/adef main():
5n/a s = "\13hello\14 \13world\14 " * 1000
6n/a p = re.compile(r"([\13\14])")
7n/a timefunc(10, p.sub, "", s)
8n/a timefunc(10, p.split, s)
9n/a timefunc(10, p.findall, s)
10n/a
11n/adef timefunc(n, func, *args, **kw):
12n/a t0 = time.perf_counter()
13n/a try:
14n/a for i in range(n):
15n/a result = func(*args, **kw)
16n/a return result
17n/a finally:
18n/a t1 = time.perf_counter()
19n/a if n > 1:
20n/a print(n, "times", end=' ')
21n/a print(func.__name__, "%.3f" % (t1-t0), "CPU seconds")
22n/a
23n/amain()