diff --git a/.benchmarks/Darwin-CPython-3.11-64bit/0001_3f253dbc281cabc8fc3a234037c880da28954a70_20241120_093422_uncommited-changes.json b/.benchmarks/Darwin-CPython-3.11-64bit/0001_3f253dbc281cabc8fc3a234037c880da28954a70_20241120_093422_uncommited-changes.json new file mode 100644 index 000000000..7af71c464 --- /dev/null +++ b/.benchmarks/Darwin-CPython-3.11-64bit/0001_3f253dbc281cabc8fc3a234037c880da28954a70_20241120_093422_uncommited-changes.json @@ -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" +} \ No newline at end of file diff --git a/.benchmarks/Darwin-CPython-3.11-64bit/0001_8e9da042ae83a00d3d49622680b51da6758aa1a3_20241120_024209.json b/.benchmarks/Darwin-CPython-3.11-64bit/0001_8e9da042ae83a00d3d49622680b51da6758aa1a3_20241120_024209.json deleted file mode 100644 index 22a52e83e..000000000 --- a/.benchmarks/Darwin-CPython-3.11-64bit/0001_8e9da042ae83a00d3d49622680b51da6758aa1a3_20241120_024209.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "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": "8e9da042ae83a00d3d49622680b51da6758aa1a3", - "time": "2024-11-20T03:41:52+01:00", - "author_time": "2024-11-20T03:41:25+01:00", - "dirty": false, - "project": "openfisca-core", - "branch": "perf/add-benchmark-to-perf-test" - }, - "benchmarks": [ - { - "group": null, - "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": 1.4624965842813253e-06, - "max": 5.641701864078641e-06, - "mean": 1.530727793695405e-06, - "stddev": 1.3133383248007482e-07, - "rounds": 50000, - "median": 1.5124969650059938e-06, - "iqr": 1.6595004126429473e-08, - "q1": 1.5042023733258247e-06, - "q3": 1.5207973774522542e-06, - "iqr_outliers": 4656, - "stddev_outliers": 956, - "outliers": "956;4656", - "ld15iqr": 1.4833000022917987e-06, - "hd15iqr": 1.5457975678145885e-06, - "ops": 653284.0156941818, - "total": 0.07653638968476802, - "iterations": 10 - } - }, - { - "group": null, - "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": 3.5170797491446135e-05, - "max": 0.0013176416046917438, - "mean": 3.781159137981013e-05, - "stddev": 1.4478194055223582e-05, - "rounds": 50000, - "median": 3.6212499253451824e-05, - "iqr": 7.58402165956802e-07, - "q1": 3.602079814299941e-05, - "q3": 3.677920030895621e-05, - "iqr_outliers": 4857, - "stddev_outliers": 870, - "outliers": "870;4857", - "ld15iqr": 3.5170797491446135e-05, - "hd15iqr": 3.792079514823854e-05, - "ops": 26446.916501217667, - "total": 1.890579568990506, - "iterations": 10 - } - } - ], - "datetime": "2024-11-20T02:42:30.223904+00:00", - "version": "5.1.0" -} \ No newline at end of file diff --git a/openfisca_core/indexed_enums/tests/test_enum.py b/openfisca_core/indexed_enums/tests/test_enum.py index 03614203a..6d355f06c 100644 --- a/openfisca_core/indexed_enums/tests/test_enum.py +++ b/openfisca_core/indexed_enums/tests/test_enum.py @@ -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) diff --git a/openfisca_core/indexed_enums/tests/test_enum_array.py b/openfisca_core/indexed_enums/tests/test_enum_array.py index 1ab247468..854c65ddf 100644 --- a/openfisca_core/indexed_enums/tests/test_enum_array.py +++ b/openfisca_core/indexed_enums/tests/test_enum_array.py @@ -28,3 +28,45 @@ def test_enum_array_any_other_operation(enum_array): """Only equality and non-equality operations are permitted.""" with pytest.raises(TypeError, match="Forbidden operation."): enum_array * 1 + + +# Benchmarking + + +@pytest.mark.benchmark(group="EnumArray.__eq__") +def test_benchmark_enum_array_eq(benchmark): + """Benchmark the `EnumArray.__eq__` method.""" + array_1 = numpy.random.choice(list(Fruit), size=50000) + array_2 = numpy.random.choice(list(Fruit), size=50000) + enum_array_1 = Fruit.encode(array_1) + enum_array_2 = Fruit.encode(array_2) + + def test(): + enum_array_1 == enum_array_2 + enum_array_1 != enum_array_2 + + benchmark.pedantic(test, iterations=100, rounds=100) + + +@pytest.mark.benchmark(group="EnumArray.decode") +def test_benchmark_enum_array_decode(benchmark): + """Benchmark the `EnumArray.decode` method.""" + array = numpy.random.choice(list(Fruit), size=50000) + enum_array = Fruit.encode(array) + + def test(): + enum_array.decode() + + benchmark.pedantic(test, iterations=100, rounds=100) + + +@pytest.mark.benchmark(group="EnumArray.decode_to_str") +def test_benchmark_enum_array_decode_to_str(benchmark): + """Benchmark the `EnumArray.decode_to_str` method.""" + array = numpy.random.choice(list(Fruit), size=50000) + enum_array = Fruit.encode(array) + + def test(): + enum_array.decode_to_str() + + benchmark.pedantic(test, iterations=100, rounds=100)