Skip to content
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
20 changes: 18 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install pandas pydot Pillow
- name: Generate coverage report
- name: Generate coverage report and benchmark report
run: |
python -m pip install pytest pytest-cov pytest-benchmark[histogram]
pytest --cov=./ --cov-report=xml
pytest --cov=./ --cov-report=xml --benchmark-autosave --benchmark-histogram=.benchmarks/histogram --benchmark-json output.json
- name: Convert coverage report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
Expand All @@ -41,8 +41,24 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Code coverage report
recreate: true
path: code-coverage-results.md
- name: Download previous benchmark report
uses: actions/cache@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Store benchmark report
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "pytest"
output-file-path: output.json
external-data-json-path: ./cache/benchmark-data.json
fail-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
summary-always: true
- name: Upload coverage to Codecov
if: ${{ github.event_name == 'push' }}
uses: codecov/codecov-action@v3
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Misc: Testing to include benchmark timings for tree creation.
- Misc: Attach benchmark timing results to pull requests.
### Changed
- Misc: Documentation to enable zooming in of images, add navigation section headers, remove some meta tags.

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ dependencies = [
"pydot",
"pytest",
"pytest-cov",
"pytest-benchmark[histogram]",
]

[tool.hatch.envs.default.scripts]
cov = "no-cov && coverage report --show-missing --omit='*/workflows/*' {args}"
cov2 = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=bigtree {args}"
cov = "no-cov && coverage report --show-missing --omit='*/workflows/*' {args} --benchmark-autosave --benchmark-histogram=.benchmarks/histogram --benchmark-json .benchmarks/output.json"
cov2 = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=bigtree {args} --benchmark-autosave --benchmark-histogram=.benchmarks/histogram --benchmark-json .benchmarks/output.json"
no-cov = "pytest . {args}"
lint = "black -l 88 ."
sort = "isort --profile black ."
Expand Down
60 changes: 60 additions & 0 deletions tests/node/test_node_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys
from unittest.mock import patch

from bigtree.node.node import Node

sys.setrecursionlimit(2000)


def run_construct_node(depth: int, width: int = 1, parent_node: Node = None) -> Node:
"""Create a balanced tree of depth `depth` and width `width`

Args:
depth (int): depth of tree
width (int): width of tree, number of children of every node
parent_node (Node): current parent node, used for recursion

Returns:
(Node)
"""
if depth > 0:
for _width in range(width):
new_node = Node(f"{depth}.{_width}", parent=parent_node)
run_construct_node(depth - 1, width, new_node)
return new_node


def test_node_benchmark_width_1_depth_10(benchmark):
benchmark.pedantic(run_construct_node, (10, 1), iterations=10, rounds=2)


def test_node_benchmark_width_1_depth_100(benchmark):
benchmark.pedantic(run_construct_node, (100, 1), iterations=10, rounds=2)


def test_node_benchmark_width_1_depth_1000(benchmark):
benchmark.pedantic(run_construct_node, (1000, 1), iterations=10, rounds=2)


def test_node_benchmark_width_2_depth_10(benchmark):
benchmark.pedantic(run_construct_node, (10, 2), iterations=10, rounds=2)


@patch("bigtree.node.basenode.ASSERTIONS", "")
def test_node_benchmark_width_1_depth_10_no_assertions(benchmark):
benchmark.pedantic(run_construct_node, (10, 1), iterations=10, rounds=2)


@patch("bigtree.node.basenode.ASSERTIONS", "")
def test_node_benchmark_width_1_depth_100_no_assertions(benchmark):
benchmark.pedantic(run_construct_node, (100, 1), iterations=10, rounds=2)


@patch("bigtree.node.basenode.ASSERTIONS", "")
def test_node_benchmark_width_1_depth_1000_no_assertions(benchmark):
benchmark.pedantic(run_construct_node, (1000, 1), iterations=10, rounds=2)


@patch("bigtree.node.basenode.ASSERTIONS", "")
def test_node_benchmark_width_2_depth_10_no_assertions(benchmark):
benchmark.pedantic(run_construct_node, (10, 2), iterations=10, rounds=2)