Skip to content

Commit db6b53c

Browse files
committed
feat: Add Codspeed benchmark
1 parent 8e07687 commit db6b53c

File tree

4 files changed

+89
-100
lines changed

4 files changed

+89
-100
lines changed

requirements-dev.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ pytest
22
black
33
flake8
44
isort
5+
pytest-codspeed
56
pytest-mock
6-
pytest-lazy-fixture
7+
pytest-lazy-fixtures
78
pytest-cov
89
pip-tools
9-
types-pytest-lazy-fixture
1010
types-setuptools
1111
mypy
1212
absolufy-imports

requirements-dev.txt

Lines changed: 57 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,79 @@
11
# This file was autogenerated by uv via the following command:
2-
# uv pip compile requirements-dev.in --constraints requirements-dev.txt --constraints requirements.txt -o requirements-dev.txt
2+
# uv pip compile requirements-dev.in --constraints requirements.txt -o requirements-dev.txt --python-version 3.8
33
absolufy-imports==0.3.1
4-
# via
5-
# -c requirements-dev.txt
6-
# -r requirements-dev.in
4+
# via -r requirements-dev.in
75
annotated-types==0.5.0
86
# via
97
# -c requirements.txt
108
# pydantic
119
argcomplete==3.6.2
1210
# via datamodel-code-generator
13-
black==24.3.0
11+
black==24.8.0
1412
# via
15-
# -c requirements-dev.txt
1613
# -r requirements-dev.in
1714
# datamodel-code-generator
18-
build==0.10.0
19-
# via
20-
# -c requirements-dev.txt
21-
# pip-tools
22-
click==8.1.7
15+
build==1.2.2.post1
16+
# via pip-tools
17+
cffi==1.17.1
18+
# via pytest-codspeed
19+
click==8.1.8
2320
# via
24-
# -c requirements-dev.txt
2521
# black
2622
# pip-tools
27-
coverage==7.3.0
28-
# via
29-
# -c requirements-dev.txt
30-
# pytest-cov
23+
coverage==7.6.1
24+
# via pytest-cov
3125
datamodel-code-generator==0.27.3
3226
# via -r requirements-dev.in
3327
exceptiongroup==1.3.0
3428
# via pytest
35-
flake8==6.1.0
36-
# via
37-
# -c requirements-dev.txt
38-
# -r requirements-dev.in
29+
filelock==3.16.1
30+
# via pytest-codspeed
31+
flake8==5.0.4
32+
# via -r requirements-dev.in
3933
genson==1.3.0
4034
# via datamodel-code-generator
35+
importlib-metadata==8.5.0
36+
# via build
4137
inflect==5.6.2
4238
# via datamodel-code-generator
43-
iniconfig==2.0.0
44-
# via
45-
# -c requirements-dev.txt
46-
# pytest
47-
isort==5.12.0
39+
iniconfig==2.1.0
40+
# via pytest
41+
isort==5.13.2
4842
# via
49-
# -c requirements-dev.txt
5043
# -r requirements-dev.in
5144
# datamodel-code-generator
5245
jinja2==3.1.6
5346
# via datamodel-code-generator
5447
markupsafe==2.1.5
5548
# via jinja2
5649
mccabe==0.7.0
50+
# via flake8
51+
mypy==1.14.1
52+
# via -r requirements-dev.in
53+
mypy-extensions==1.1.0
5754
# via
58-
# -c requirements-dev.txt
59-
# flake8
60-
mypy==1.5.1
61-
# via
62-
# -c requirements-dev.txt
63-
# -r requirements-dev.in
64-
mypy-extensions==1.0.0
65-
# via
66-
# -c requirements-dev.txt
6755
# black
6856
# mypy
69-
packaging==23.1
57+
packaging==25.0
7058
# via
71-
# -c requirements-dev.txt
7259
# black
7360
# build
7461
# datamodel-code-generator
7562
# pytest
76-
pathspec==0.11.2
77-
# via
78-
# -c requirements-dev.txt
79-
# black
63+
pathspec==0.12.1
64+
# via black
8065
pip==25.0.1
8166
# via pip-tools
82-
pip-tools==7.3.0
83-
# via
84-
# -c requirements-dev.txt
85-
# -r requirements-dev.in
86-
platformdirs==3.10.0
87-
# via
88-
# -c requirements-dev.txt
89-
# black
90-
pluggy==1.2.0
91-
# via
92-
# -c requirements-dev.txt
93-
# pytest
94-
pycodestyle==2.11.0
95-
# via
96-
# -c requirements-dev.txt
97-
# flake8
67+
pip-tools==7.5.0
68+
# via -r requirements-dev.in
69+
platformdirs==4.3.6
70+
# via black
71+
pluggy==1.5.0
72+
# via pytest
73+
pycodestyle==2.9.1
74+
# via flake8
75+
pycparser==2.22
76+
# via cffi
9877
pydantic==2.4.0
9978
# via
10079
# -c requirements.txt
@@ -103,33 +82,27 @@ pydantic-core==2.10.0
10382
# via
10483
# -c requirements.txt
10584
# pydantic
106-
pyflakes==3.1.0
107-
# via
108-
# -c requirements-dev.txt
109-
# flake8
110-
pyproject-hooks==1.0.0
85+
pyflakes==2.5.0
86+
# via flake8
87+
pyproject-hooks==1.2.0
11188
# via
112-
# -c requirements-dev.txt
11389
# build
114-
pytest==7.4.0
90+
# pip-tools
91+
pytest==8.3.5
11592
# via
116-
# -c requirements-dev.txt
11793
# -r requirements-dev.in
94+
# pytest-codspeed
11895
# pytest-cov
119-
# pytest-lazy-fixture
96+
# pytest-lazy-fixtures
12097
# pytest-mock
121-
pytest-cov==4.1.0
122-
# via
123-
# -c requirements-dev.txt
124-
# -r requirements-dev.in
125-
pytest-lazy-fixture==0.6.3
126-
# via
127-
# -c requirements-dev.txt
128-
# -r requirements-dev.in
129-
pytest-mock==3.11.1
130-
# via
131-
# -c requirements-dev.txt
132-
# -r requirements-dev.in
98+
pytest-codspeed==2.2.1
99+
# via -r requirements-dev.in
100+
pytest-cov==5.0.0
101+
# via -r requirements-dev.in
102+
pytest-lazy-fixtures==1.3.4
103+
# via -r requirements-dev.in
104+
pytest-mock==3.14.1
105+
# via -r requirements-dev.in
133106
pyyaml==6.0.2
134107
# via datamodel-code-generator
135108
setuptools==75.3.2
@@ -142,27 +115,19 @@ tomli==2.2.1
142115
# datamodel-code-generator
143116
# mypy
144117
# pip-tools
145-
# pyproject-hooks
146118
# pytest
147-
types-pytest-lazy-fixture==0.6.3.4
148-
# via
149-
# -c requirements-dev.txt
150-
# -r requirements-dev.in
151-
types-setuptools==68.2.0.0
152-
# via
153-
# -c requirements-dev.txt
154-
# -r requirements-dev.in
119+
types-setuptools==75.8.0.20250110
120+
# via -r requirements-dev.in
155121
typing-extensions==4.8.0
156122
# via
157-
# -c requirements-dev.txt
158123
# -c requirements.txt
159124
# annotated-types
160125
# black
161126
# exceptiongroup
162127
# mypy
163128
# pydantic
164129
# pydantic-core
165-
wheel==0.41.2
166-
# via
167-
# -c requirements-dev.txt
168-
# pip-tools
130+
wheel==0.45.1
131+
# via pip-tools
132+
zipp==3.20.2
133+
# via importlib-metadata

tests/engine_tests/test_engine.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
import pytest
55
from pydantic import BaseModel
6+
from pytest_codspeed import BenchmarkFixture # type: ignore[import-untyped]
67

8+
from flag_engine.context.mappers import map_environment_identity_to_context
79
from flag_engine.engine import get_identity_feature_states
810
from flag_engine.environments.models import EnvironmentModel
911
from flag_engine.identities.models import IdentityModel
12+
from flag_engine.segments.evaluator import get_evaluation_result
1013

1114
MODULE_PATH = Path(__file__).parent.resolve()
1215

@@ -51,11 +54,14 @@ def _extract_test_cases(
5154
]
5255

5356

57+
TEST_CASES = _extract_test_cases(
58+
MODULE_PATH / "engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json"
59+
)
60+
61+
5462
@pytest.mark.parametrize(
5563
"environment_model, identity_model, api_response",
56-
_extract_test_cases(
57-
MODULE_PATH / "engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json"
58-
),
64+
TEST_CASES,
5965
)
6066
def test_engine(
6167
environment_model: EnvironmentModel,
@@ -79,3 +85,21 @@ def test_engine(
7985
fs.feature.name: fs.get_value(identity_model.django_id)
8086
for fs in engine_response
8187
} == {flag["feature"]["name"]: flag["feature_state_value"] for flag in api_flags}
88+
89+
90+
@pytest.mark.benchmark
91+
def test_engine_benchmark(benchmark: BenchmarkFixture) -> None: # type: ignore[no-any-unimported]
92+
contexts = []
93+
for environment_model, identity_model, _ in TEST_CASES:
94+
contexts.append(
95+
map_environment_identity_to_context(
96+
environment=environment_model,
97+
identity=identity_model,
98+
override_traits=None,
99+
)
100+
)
101+
102+
@benchmark
103+
def __() -> None:
104+
for context in contexts:
105+
get_evaluation_result(context)

tests/unit/segments/test_segments_evaluator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typing
22

33
import pytest
4-
from pytest_lazyfixture import lazy_fixture
4+
from pytest_lazy_fixtures import lf
55
from pytest_mock import MockerFixture
66

77
import flag_engine.segments.evaluator
@@ -367,8 +367,8 @@ def test_context_in_segment_percentage_split__trait_value__calls_expected(
367367
@pytest.mark.parametrize(
368368
"operator, property_, expected_result",
369369
(
370-
(constants.IS_SET, lazy_fixture("segment_condition_property"), True),
371-
(constants.IS_NOT_SET, lazy_fixture("segment_condition_property"), False),
370+
(constants.IS_SET, lf("segment_condition_property"), True),
371+
(constants.IS_NOT_SET, lf("segment_condition_property"), False),
372372
(constants.IS_SET, "random_property", False),
373373
(constants.IS_NOT_SET, "random_property", True),
374374
),

0 commit comments

Comments
 (0)