Skip to content

Commit e8b0acf

Browse files
committed
test: add perf tests to EnumArray
1 parent 196145a commit e8b0acf

File tree

4 files changed

+268
-121
lines changed

4 files changed

+268
-121
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"machine_info": {
3+
"node": "diotimac2.local",
4+
"processor": "arm",
5+
"machine": "arm64",
6+
"python_compiler": "Clang 18.1.8 ",
7+
"python_implementation": "CPython",
8+
"python_implementation_version": "3.11.10",
9+
"python_version": "3.11.10",
10+
"python_build": [
11+
"main",
12+
"Oct 1 2024 00:26:49"
13+
],
14+
"release": "23.4.0",
15+
"system": "Darwin",
16+
"cpu": {
17+
"python_version": "3.11.10.final.0 (64 bit)",
18+
"cpuinfo_version": [
19+
9,
20+
0,
21+
0
22+
],
23+
"cpuinfo_version_string": "9.0.0",
24+
"arch": "ARM_8",
25+
"bits": 64,
26+
"count": 8,
27+
"arch_string_raw": "arm64",
28+
"brand_raw": "Apple M1"
29+
}
30+
},
31+
"commit_info": {
32+
"id": "3f253dbc281cabc8fc3a234037c880da28954a70",
33+
"time": "2024-11-20T10:27:33+01:00",
34+
"author_time": "2024-11-20T10:27:23+01:00",
35+
"dirty": true,
36+
"project": "openfisca-core",
37+
"branch": "perf/add-benchmark-to-perf-test"
38+
},
39+
"benchmarks": [
40+
{
41+
"group": "Enum.__eq__",
42+
"name": "test_benchmark_enum_eq",
43+
"fullname": "openfisca_core/indexed_enums/tests/test_enum.py::test_benchmark_enum_eq",
44+
"params": null,
45+
"param": null,
46+
"extra_info": {},
47+
"options": {
48+
"disable_gc": false,
49+
"timer": "perf_counter",
50+
"min_rounds": 5,
51+
"max_time": 1.0,
52+
"min_time": 5e-06,
53+
"warmup": false
54+
},
55+
"stats": {
56+
"min": 6.088025000099151e-06,
57+
"max": 6.279845799872419e-06,
58+
"mean": 6.152403132000472e-06,
59+
"stddev": 3.371609720219699e-08,
60+
"rounds": 100,
61+
"median": 6.1525833501036685e-06,
62+
"iqr": 4.103329993085945e-08,
63+
"q1": 6.129739600055473e-06,
64+
"q3": 6.170772899986332e-06,
65+
"iqr_outliers": 3,
66+
"stddev_outliers": 29,
67+
"outliers": "29;3",
68+
"ld15iqr": 6.088025000099151e-06,
69+
"hd15iqr": 6.234904200027813e-06,
70+
"ops": 162538.11373294174,
71+
"total": 0.0006152403132000474,
72+
"iterations": 10000
73+
}
74+
},
75+
{
76+
"group": "Enum.encode",
77+
"name": "test_benchmark_enum_encode",
78+
"fullname": "openfisca_core/indexed_enums/tests/test_enum.py::test_benchmark_enum_encode",
79+
"params": null,
80+
"param": null,
81+
"extra_info": {},
82+
"options": {
83+
"disable_gc": false,
84+
"timer": "perf_counter",
85+
"min_rounds": 5,
86+
"max_time": 1.0,
87+
"min_time": 5e-06,
88+
"warmup": false
89+
},
90+
"stats": {
91+
"min": 0.0011622333000559592,
92+
"max": 0.001228883299882,
93+
"mean": 0.0011774051709980994,
94+
"stddev": 1.044335238367826e-05,
95+
"rounds": 100,
96+
"median": 0.0011762395999539877,
97+
"iqr": 9.822950050874819e-06,
98+
"q1": 0.001170379149971268,
99+
"q3": 0.001180202100022143,
100+
"iqr_outliers": 6,
101+
"stddev_outliers": 20,
102+
"outliers": "20;6",
103+
"ld15iqr": 0.0011622333000559592,
104+
"hd15iqr": 0.0011961624999457855,
105+
"ops": 849.3252999324686,
106+
"total": 0.11774051709980991,
107+
"iterations": 10
108+
}
109+
},
110+
{
111+
"group": "EnumArray.__eq__",
112+
"name": "test_benchmark_enum_array_eq",
113+
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_eq",
114+
"params": null,
115+
"param": null,
116+
"extra_info": {},
117+
"options": {
118+
"disable_gc": false,
119+
"timer": "perf_counter",
120+
"min_rounds": 5,
121+
"max_time": 1.0,
122+
"min_time": 5e-06,
123+
"warmup": false
124+
},
125+
"stats": {
126+
"min": 8.837080004013843e-06,
127+
"max": 9.454999999434221e-06,
128+
"mean": 8.931775500968797e-06,
129+
"stddev": 9.783811489338906e-08,
130+
"rounds": 100,
131+
"median": 8.893335007087444e-06,
132+
"iqr": 1.1583500054257429e-07,
133+
"q1": 8.863125003699679e-06,
134+
"q3": 8.978960004242253e-06,
135+
"iqr_outliers": 3,
136+
"stddev_outliers": 10,
137+
"outliers": "10;3",
138+
"ld15iqr": 8.837080004013843e-06,
139+
"hd15iqr": 9.189590000460158e-06,
140+
"ops": 111959.82253377662,
141+
"total": 0.0008931775500968795,
142+
"iterations": 100
143+
}
144+
},
145+
{
146+
"group": "EnumArray.decode",
147+
"name": "test_benchmark_enum_array_decode",
148+
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_decode",
149+
"params": null,
150+
"param": null,
151+
"extra_info": {},
152+
"options": {
153+
"disable_gc": false,
154+
"timer": "perf_counter",
155+
"min_rounds": 5,
156+
"max_time": 1.0,
157+
"min_time": 5e-06,
158+
"warmup": false
159+
},
160+
"stats": {
161+
"min": 0.0007508641700042062,
162+
"max": 0.0013628329199855216,
163+
"mean": 0.0007727886379994743,
164+
"stddev": 7.314420787878281e-05,
165+
"rounds": 100,
166+
"median": 0.0007575662499948522,
167+
"iqr": 1.1167909988216802e-05,
168+
"q1": 0.0007547029200031829,
169+
"q3": 0.0007658708299913997,
170+
"iqr_outliers": 9,
171+
"stddev_outliers": 2,
172+
"outliers": "2;9",
173+
"ld15iqr": 0.0007508641700042062,
174+
"hd15iqr": 0.0007828712500122493,
175+
"ops": 1294.0148843139184,
176+
"total": 0.0772788637999474,
177+
"iterations": 100
178+
}
179+
},
180+
{
181+
"group": "EnumArray.decode_to_str",
182+
"name": "test_benchmark_enum_array_decode_to_str",
183+
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_decode_to_str",
184+
"params": null,
185+
"param": null,
186+
"extra_info": {},
187+
"options": {
188+
"disable_gc": false,
189+
"timer": "perf_counter",
190+
"min_rounds": 5,
191+
"max_time": 1.0,
192+
"min_time": 5e-06,
193+
"warmup": false
194+
},
195+
"stats": {
196+
"min": 0.0008599420899918186,
197+
"max": 0.000904484170005162,
198+
"mean": 0.000868757312199159,
199+
"stddev": 8.210009405774617e-06,
200+
"rounds": 100,
201+
"median": 0.000866150829997423,
202+
"iqr": 4.8420749953947875e-06,
203+
"q1": 0.0008642458350004745,
204+
"q3": 0.0008690879099958693,
205+
"iqr_outliers": 12,
206+
"stddev_outliers": 13,
207+
"outliers": "13;12",
208+
"ld15iqr": 0.0008599420899918186,
209+
"hd15iqr": 0.0008774329200059583,
210+
"ops": 1151.069448231308,
211+
"total": 0.0868757312199159,
212+
"iterations": 100
213+
}
214+
}
215+
],
216+
"datetime": "2024-11-20T09:34:47.304646+00:00",
217+
"version": "5.1.0"
218+
}

.benchmarks/Darwin-CPython-3.11-64bit/0001_8e9da042ae83a00d3d49622680b51da6758aa1a3_20241120_024209.json

Lines changed: 0 additions & 113 deletions
This file was deleted.

openfisca_core/indexed_enums/tests/test_enum.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ def test_enum_encode_with_any_sequence():
141141
@pytest.mark.benchmark(group="Enum.__eq__")
142142
def test_benchmark_enum_eq(benchmark):
143143
"""Benchmark the `__eq__` method."""
144+
array = numpy.random.choice([*list(Animal), *list(Colour)], size=50000)
144145

145146
def test():
146-
for animal in Animal:
147-
for colour in Colour:
148-
assert animal != colour
147+
animal_1, animal_2 = numpy.random.choice(array, size=2)
148+
animal_1 == animal_2
149+
animal_1 != animal_2
149150

150-
benchmark.pedantic(test, iterations=10, rounds=50000)
151+
benchmark.pedantic(test, iterations=10000, rounds=100)
151152

152153

153154
@pytest.mark.benchmark(group="Enum.encode")
154155
def test_benchmark_enum_encode(benchmark):
155156
"""Benchmark the `Enum.encode` method."""
156-
array = numpy.array([Animal.DOG, Animal.CAT, Animal.DOG])
157+
array = numpy.random.choice(["INCARNADINE", "TURQUOISE", "AMARANTH"], size=50000)
157158

158159
def test():
159-
enum_array = Animal.encode(array)
160-
assert_array_equal(enum_array, numpy.array([1, 0, 1]))
160+
Colour.encode(array)
161161

162-
benchmark.pedantic(test, iterations=10, rounds=50000)
162+
benchmark.pedantic(test, iterations=10, rounds=100)

0 commit comments

Comments
 (0)