Skip to content

Commit 01d3e81

Browse files
Add coverage benchmark (#213)
1 parent f195616 commit 01d3e81

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ pyperformance/tests/data/cpython/
2121

2222
# Created by the tox program
2323
.tox/
24+
25+
# coverage
26+
.coverage

pyperformance/data-files/benchmarks/MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ async_tree <local>
66
async_tree_cpu_io_mixed <local:async_tree>
77
async_tree_io <local:async_tree>
88
async_tree_memoization <local:async_tree>
9+
coverage <local>
910
generators <local>
1011
chameleon <local>
1112
chaos <local>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "pyperformance_bm_coverage"
3+
requires-python = ">=3.8"
4+
dependencies = [
5+
"pyperf",
6+
"coverage",
7+
]
8+
urls = {repository = "https://github.com/python/pyperformance"}
9+
dynamic = ["version"]
10+
11+
[tool.pyperformance]
12+
name = "coverage"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage==6.4.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Benchmark coverage performance with a recursive fibonacci function.
3+
"""
4+
5+
import coverage
6+
import pyperf
7+
8+
9+
def fibonacci(n: int) -> int:
10+
if n <= 1:
11+
return n
12+
return fibonacci(n - 1) + fibonacci(n - 2)
13+
14+
15+
def bench_coverage(loops: int) -> None:
16+
range_it = range(loops)
17+
cov = coverage.Coverage()
18+
cov.start()
19+
t0 = pyperf.perf_counter()
20+
for _ in range_it:
21+
fibonacci(25)
22+
cov.stop()
23+
return pyperf.perf_counter() - t0
24+
25+
26+
if __name__ == "__main__":
27+
runner = pyperf.Runner()
28+
runner.metadata['description'] = "Benchmark coverage"
29+
runner.bench_time_func('coverage', bench_coverage)

0 commit comments

Comments
 (0)