Skip to content

Commit

Permalink
Add coverage benchmark (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 authored Jun 6, 2022
1 parent f195616 commit 01d3e81
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
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)

0 comments on commit 01d3e81

Please sign in to comment.