Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage benchmark #213

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ pyperformance/tests/data/cpython/

# Created by the tox program
.tox/

# coverage
.coverage
1 change: 1 addition & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async_tree <local>
async_tree_cpu_io_mixed <local:async_tree>
async_tree_io <local:async_tree>
async_tree_memoization <local:async_tree>
coverage <local>
generators <local>
chameleon <local>
chaos <local>
Expand Down
12 changes: 12 additions & 0 deletions pyperformance/data-files/benchmarks/bm_coverage/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "pyperformance_bm_coverage"
requires-python = ">=3.8"
dependencies = [
"pyperf",
"coverage",
]
urls = {repository = "https://github.com/python/pyperformance"}
dynamic = ["version"]

[tool.pyperformance]
name = "coverage"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage==6.4.1
29 changes: 29 additions & 0 deletions pyperformance/data-files/benchmarks/bm_coverage/run_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Benchmark coverage performance with a recursive fibonacci function.
"""

import coverage
import pyperf


def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)


def bench_coverage(loops: int) -> None:
range_it = range(loops)
cov = coverage.Coverage()
cov.start()
t0 = pyperf.perf_counter()
for _ in range_it:
fibonacci(25)
cov.stop()
return pyperf.perf_counter() - t0


if __name__ == "__main__":
runner = pyperf.Runner()
runner.metadata['description'] = "Benchmark coverage"
runner.bench_time_func('coverage', bench_coverage)