Skip to content

Commit

Permalink
test: add perf tests to EnumArray
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Nov 20, 2024
1 parent 196145a commit e8b0acf
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"machine_info": {
"node": "diotimac2.local",
"processor": "arm",
"machine": "arm64",
"python_compiler": "Clang 18.1.8 ",
"python_implementation": "CPython",
"python_implementation_version": "3.11.10",
"python_version": "3.11.10",
"python_build": [
"main",
"Oct 1 2024 00:26:49"
],
"release": "23.4.0",
"system": "Darwin",
"cpu": {
"python_version": "3.11.10.final.0 (64 bit)",
"cpuinfo_version": [
9,
0,
0
],
"cpuinfo_version_string": "9.0.0",
"arch": "ARM_8",
"bits": 64,
"count": 8,
"arch_string_raw": "arm64",
"brand_raw": "Apple M1"
}
},
"commit_info": {
"id": "3f253dbc281cabc8fc3a234037c880da28954a70",
"time": "2024-11-20T10:27:33+01:00",
"author_time": "2024-11-20T10:27:23+01:00",
"dirty": true,
"project": "openfisca-core",
"branch": "perf/add-benchmark-to-perf-test"
},
"benchmarks": [
{
"group": "Enum.__eq__",
"name": "test_benchmark_enum_eq",
"fullname": "openfisca_core/indexed_enums/tests/test_enum.py::test_benchmark_enum_eq",
"params": null,
"param": null,
"extra_info": {},
"options": {
"disable_gc": false,
"timer": "perf_counter",
"min_rounds": 5,
"max_time": 1.0,
"min_time": 5e-06,
"warmup": false
},
"stats": {
"min": 6.088025000099151e-06,
"max": 6.279845799872419e-06,
"mean": 6.152403132000472e-06,
"stddev": 3.371609720219699e-08,
"rounds": 100,
"median": 6.1525833501036685e-06,
"iqr": 4.103329993085945e-08,
"q1": 6.129739600055473e-06,
"q3": 6.170772899986332e-06,
"iqr_outliers": 3,
"stddev_outliers": 29,
"outliers": "29;3",
"ld15iqr": 6.088025000099151e-06,
"hd15iqr": 6.234904200027813e-06,
"ops": 162538.11373294174,
"total": 0.0006152403132000474,
"iterations": 10000
}
},
{
"group": "Enum.encode",
"name": "test_benchmark_enum_encode",
"fullname": "openfisca_core/indexed_enums/tests/test_enum.py::test_benchmark_enum_encode",
"params": null,
"param": null,
"extra_info": {},
"options": {
"disable_gc": false,
"timer": "perf_counter",
"min_rounds": 5,
"max_time": 1.0,
"min_time": 5e-06,
"warmup": false
},
"stats": {
"min": 0.0011622333000559592,
"max": 0.001228883299882,
"mean": 0.0011774051709980994,
"stddev": 1.044335238367826e-05,
"rounds": 100,
"median": 0.0011762395999539877,
"iqr": 9.822950050874819e-06,
"q1": 0.001170379149971268,
"q3": 0.001180202100022143,
"iqr_outliers": 6,
"stddev_outliers": 20,
"outliers": "20;6",
"ld15iqr": 0.0011622333000559592,
"hd15iqr": 0.0011961624999457855,
"ops": 849.3252999324686,
"total": 0.11774051709980991,
"iterations": 10
}
},
{
"group": "EnumArray.__eq__",
"name": "test_benchmark_enum_array_eq",
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_eq",
"params": null,
"param": null,
"extra_info": {},
"options": {
"disable_gc": false,
"timer": "perf_counter",
"min_rounds": 5,
"max_time": 1.0,
"min_time": 5e-06,
"warmup": false
},
"stats": {
"min": 8.837080004013843e-06,
"max": 9.454999999434221e-06,
"mean": 8.931775500968797e-06,
"stddev": 9.783811489338906e-08,
"rounds": 100,
"median": 8.893335007087444e-06,
"iqr": 1.1583500054257429e-07,
"q1": 8.863125003699679e-06,
"q3": 8.978960004242253e-06,
"iqr_outliers": 3,
"stddev_outliers": 10,
"outliers": "10;3",
"ld15iqr": 8.837080004013843e-06,
"hd15iqr": 9.189590000460158e-06,
"ops": 111959.82253377662,
"total": 0.0008931775500968795,
"iterations": 100
}
},
{
"group": "EnumArray.decode",
"name": "test_benchmark_enum_array_decode",
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_decode",
"params": null,
"param": null,
"extra_info": {},
"options": {
"disable_gc": false,
"timer": "perf_counter",
"min_rounds": 5,
"max_time": 1.0,
"min_time": 5e-06,
"warmup": false
},
"stats": {
"min": 0.0007508641700042062,
"max": 0.0013628329199855216,
"mean": 0.0007727886379994743,
"stddev": 7.314420787878281e-05,
"rounds": 100,
"median": 0.0007575662499948522,
"iqr": 1.1167909988216802e-05,
"q1": 0.0007547029200031829,
"q3": 0.0007658708299913997,
"iqr_outliers": 9,
"stddev_outliers": 2,
"outliers": "2;9",
"ld15iqr": 0.0007508641700042062,
"hd15iqr": 0.0007828712500122493,
"ops": 1294.0148843139184,
"total": 0.0772788637999474,
"iterations": 100
}
},
{
"group": "EnumArray.decode_to_str",
"name": "test_benchmark_enum_array_decode_to_str",
"fullname": "openfisca_core/indexed_enums/tests/test_enum_array.py::test_benchmark_enum_array_decode_to_str",
"params": null,
"param": null,
"extra_info": {},
"options": {
"disable_gc": false,
"timer": "perf_counter",
"min_rounds": 5,
"max_time": 1.0,
"min_time": 5e-06,
"warmup": false
},
"stats": {
"min": 0.0008599420899918186,
"max": 0.000904484170005162,
"mean": 0.000868757312199159,
"stddev": 8.210009405774617e-06,
"rounds": 100,
"median": 0.000866150829997423,
"iqr": 4.8420749953947875e-06,
"q1": 0.0008642458350004745,
"q3": 0.0008690879099958693,
"iqr_outliers": 12,
"stddev_outliers": 13,
"outliers": "13;12",
"ld15iqr": 0.0008599420899918186,
"hd15iqr": 0.0008774329200059583,
"ops": 1151.069448231308,
"total": 0.0868757312199159,
"iterations": 100
}
}
],
"datetime": "2024-11-20T09:34:47.304646+00:00",
"version": "5.1.0"
}

This file was deleted.

16 changes: 8 additions & 8 deletions openfisca_core/indexed_enums/tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ def test_enum_encode_with_any_sequence():
@pytest.mark.benchmark(group="Enum.__eq__")
def test_benchmark_enum_eq(benchmark):
"""Benchmark the `__eq__` method."""
array = numpy.random.choice([*list(Animal), *list(Colour)], size=50000)

def test():
for animal in Animal:
for colour in Colour:
assert animal != colour
animal_1, animal_2 = numpy.random.choice(array, size=2)
animal_1 == animal_2
animal_1 != animal_2

benchmark.pedantic(test, iterations=10, rounds=50000)
benchmark.pedantic(test, iterations=10000, rounds=100)


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

def test():
enum_array = Animal.encode(array)
assert_array_equal(enum_array, numpy.array([1, 0, 1]))
Colour.encode(array)

benchmark.pedantic(test, iterations=10, rounds=50000)
benchmark.pedantic(test, iterations=10, rounds=100)
Loading

0 comments on commit e8b0acf

Please sign in to comment.