Skip to content

Commit

Permalink
benchmark info data access
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Mar 28, 2024
1 parent d905bba commit 0c1f0d7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
33 changes: 32 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ charset-normalizer = "^3.2"
pylint = ">=3.0"
pytest = ">=7.4"
pytest-cov = ">=4.0"
pytest-benchmark = ">=4.0"
pytest-mypy-plugins = ">=1.11"
types-requests = "^2.28"

Expand Down Expand Up @@ -75,7 +76,7 @@ src_paths = ["zammadoo", "tests"]
# see: https://pytest-cov.readthedocs.io/en/latest/config.html
[tool.pytest.ini_options]
minversion = "7.4"
addopts = "tests -v --tb=short --cov=zammadoo --cov-report html --mypy-only-local-stub"
addopts = "tests -v --tb=short --cov=zammadoo --cov-report html --mypy-only-local-stub --benchmark-max-time=0.1"
cache_dir = ".cache/pytest"
markers = ["no_record"]

Expand Down
45 changes: 45 additions & 0 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from timeit import timeit

import pytest

from zammadoo import Client
from zammadoo.tickets import Ticket
from zammadoo.users import User

number = int(1e5)


@pytest.fixture(scope="module")
def info_ticket() -> Ticket:
client = Client("https://localhost/api/v1", http_token="myfaketoken")
info = {"id": 123, "title": "some title", "created_at": "2024-03-18T22:43:07.089Z"}
return client.tickets(123, info=info)


@pytest.fixture(scope="module")
def info_user() -> User:
client = Client("https://localhost/api/v1", http_token="myfaketoken")
info = {"id": 123, "login": "john.doe@pytest"}
return client.users(123, info=info)


def test_info_attribute(info_ticket, benchmark):
benchmark(timeit, "ticket.id", number=number, globals={"ticket": info_ticket})


def test_info_getattr(info_ticket, benchmark):
benchmark(timeit, "ticket.title", number=number, globals={"ticket": info_ticket})


def test_info_getitem(info_ticket, benchmark):
benchmark(timeit, "ticket['title']", number=number, globals={"ticket": info_ticket})


def test_info_datetime(info_ticket, benchmark):
benchmark(
timeit, "ticket.created_at", number=number, globals={"ticket": info_ticket}
)


def test_info_descriptor(info_user, benchmark):
benchmark(timeit, "user.name", number=number, globals={"user": info_user})

0 comments on commit 0c1f0d7

Please sign in to comment.