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

test: add time-to-show #28

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ jobs:
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}

benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: tlambert03/setup-qt-libs@v1
- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: install
run: |
python -m pip install .[test,pyqt,vispy,pygfx]
python -m pip install pytest-codspeed

- name: Run benchmarks
uses: CodSpeedHQ/action@v3
with:
run: pytest --codspeed -v --color=yes

deploy:
name: Deploy
needs: test
Expand Down
29 changes: 29 additions & 0 deletions tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

import sys
import unittest.mock
from typing import TYPE_CHECKING, Any

import numpy as np
import pytest

if TYPE_CHECKING:
from pytest_benchmark.fixture import BenchmarkFixture

if all(x not in {"--codspeed", "tests/test_benchmarks.py"} for x in sys.argv):
pytest.skip("use --benchmark to run benchmark", allow_module_level=True)


def _show_viewer(data: np.ndarray) -> None:
import ndv

ndv.imshow(data)


def test_time_to_show(benchmark: BenchmarkFixture, qapp: Any) -> None:
data = np.random.randint(0, 255, size=(10, 256, 256), dtype=np.uint8)
for k in list(sys.modules):
if k.startswith(("ndv", "superqt", "vispy", "pygfx", "wgpu", "PyQt", "PySide")):
del sys.modules[k]
with unittest.mock.patch.object(qapp, "exec"):
benchmark.pedantic(_show_viewer, (data,), iterations=1, rounds=1)
Loading