From 4510f0b48d6c6268acb4bd3c12f2e1df11b0dad3 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Wed, 8 Jun 2022 23:38:18 +0300 Subject: [PATCH 1/9] Port pprint performance tests --- pyperformance/data-files/benchmarks/MANIFEST | 1 + .../benchmarks/bm_from_stdlib/pyproject.toml | 9 +++++++ .../bm_from_stdlib/run_benchmark.py | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml create mode 100644 pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index 36992db1..eacde195 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -18,6 +18,7 @@ django_template dulwich_log fannkuch float +from_stdlib genshi go hexiom diff --git a/pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml b/pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml new file mode 100644 index 00000000..ce4e1e82 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "pyperformance_bm_from_stdlib" +requires-python = ">=3.8" +dependencies = ["pyperf"] +urls = {repository = "https://github.com/python/pyperformance"} +dynamic = ["version"] + +[tool.pyperformance] +name = "from_stdlib" diff --git a/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py new file mode 100644 index 00000000..a406f929 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py @@ -0,0 +1,24 @@ +"""Various benchmarks previously stored inside the Python stdlib. + +Ported here by Oleg Iarygin. +""" + +import pyperf + + +def benchmark_pprint(runner): + """Moved from `python -m pprint`.""" + from pprint import PrettyPrinter + printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 + p = PrettyPrinter() + + runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) + runner.bench_func('pformat', p.pformat, printable) + + +if __name__ == "__main__": + runner = pyperf.Runner() + cmd = runner.argparser + + args = runner.parse_args() + benchmark_pprint(runner) From 862dfc2e2c92d35f77a3d7767668764c7dae722e Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 22:59:36 +0300 Subject: [PATCH 2/9] Benchmark _safe_repr only if it exists --- .../data-files/benchmarks/bm_from_stdlib/run_benchmark.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py index a406f929..d3f99bdb 100644 --- a/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py @@ -12,7 +12,9 @@ def benchmark_pprint(runner): printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 p = PrettyPrinter() - runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) + # Support CPython before 3.10 and non-CPython implementations + if hasattr(p, '_safe_repr'): + runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) runner.bench_func('pformat', p.pformat, printable) From 2eab79cec1e0b29e06db8a977d94e932f492adbd Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:16:43 +0300 Subject: [PATCH 3/9] Rename the benchmark --- pyperformance/data-files/benchmarks/MANIFEST | 2 +- .../{bm_from_stdlib => bm_pprint}/pyproject.toml | 4 ++-- .../{bm_from_stdlib => bm_pprint}/run_benchmark.py | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) rename pyperformance/data-files/benchmarks/{bm_from_stdlib => bm_pprint}/pyproject.toml (74%) rename pyperformance/data-files/benchmarks/{bm_from_stdlib => bm_pprint}/run_benchmark.py (70%) diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index eacde195..43489311 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -18,7 +18,6 @@ django_template dulwich_log fannkuch float -from_stdlib genshi go hexiom @@ -40,6 +39,7 @@ pickle_dict pickle_list pickle_pure_python pidigits +pprint pyflate python_startup python_startup_no_site diff --git a/pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml b/pyperformance/data-files/benchmarks/bm_pprint/pyproject.toml similarity index 74% rename from pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml rename to pyperformance/data-files/benchmarks/bm_pprint/pyproject.toml index ce4e1e82..b0b1842f 100644 --- a/pyperformance/data-files/benchmarks/bm_from_stdlib/pyproject.toml +++ b/pyperformance/data-files/benchmarks/bm_pprint/pyproject.toml @@ -1,9 +1,9 @@ [project] -name = "pyperformance_bm_from_stdlib" +name = "pyperformance_bm_pprint" requires-python = ">=3.8" dependencies = ["pyperf"] urls = {repository = "https://github.com/python/pyperformance"} dynamic = ["version"] [tool.pyperformance] -name = "from_stdlib" +name = "pprint" diff --git a/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py similarity index 70% rename from pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py rename to pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index d3f99bdb..b1c92662 100644 --- a/pyperformance/data-files/benchmarks/bm_from_stdlib/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -1,14 +1,15 @@ -"""Various benchmarks previously stored inside the Python stdlib. +"""Test the performance of pprint.PrettyPrinter. -Ported here by Oleg Iarygin. +This benchmark was available as `python -m pprint` until Python 3.12. + +Authors: Fred Drake (original), Oleg Iarygin (pyperformance port). """ +from pprint import PrettyPrinter import pyperf def benchmark_pprint(runner): - """Moved from `python -m pprint`.""" - from pprint import PrettyPrinter printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 p = PrettyPrinter() From fa85a5c3671045b201982a314f217719d4e66de2 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:25:47 +0300 Subject: [PATCH 4/9] Remove a spurious `cmd` variable --- pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index b1c92662..7ad2269b 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -21,7 +21,6 @@ def benchmark_pprint(runner): if __name__ == "__main__": runner = pyperf.Runner() - cmd = runner.argparser args = runner.parse_args() benchmark_pprint(runner) From d2122a06c413686a37378912c4fa85e2dfa37914 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:27:31 +0300 Subject: [PATCH 5/9] Move constant object to a module level --- .../data-files/benchmarks/bm_pprint/run_benchmark.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index 7ad2269b..bebe2c4c 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -9,10 +9,11 @@ import pyperf -def benchmark_pprint(runner): - printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 - p = PrettyPrinter() +printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 +p = PrettyPrinter() + +def benchmark_pprint(runner): # Support CPython before 3.10 and non-CPython implementations if hasattr(p, '_safe_repr'): runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) From fbf2e30b57a6e8f37227c0c1bd832793871edc1f Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:28:14 +0300 Subject: [PATCH 6/9] Add a description --- pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index bebe2c4c..c6540ff4 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -22,6 +22,7 @@ def benchmark_pprint(runner): if __name__ == "__main__": runner = pyperf.Runner() + runner.metadata['description'] = "pprint benchmark" args = runner.parse_args() benchmark_pprint(runner) From aa267019cb9c7a37bb525f13bd7350603dc8544e Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:29:18 +0300 Subject: [PATCH 7/9] Rename benchmark labels --- .../data-files/benchmarks/bm_pprint/run_benchmark.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index c6540ff4..494001d1 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -16,8 +16,9 @@ def benchmark_pprint(runner): # Support CPython before 3.10 and non-CPython implementations if hasattr(p, '_safe_repr'): - runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) - runner.bench_func('pformat', p.pformat, printable) + runner.bench_func('pprint_safe_repr', p._safe_repr, printable, + {}, None, 0) + runner.bench_func('pprint_pformat', p.pformat, printable) if __name__ == "__main__": From 7aabc1374f2b69f3dc6a01850044bf099582f373 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:44:29 +0300 Subject: [PATCH 8/9] Make the benchmark top-level --- .../benchmarks/bm_pprint/run_benchmark.py | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index 494001d1..a3ae55f8 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -5,25 +5,18 @@ Authors: Fred Drake (original), Oleg Iarygin (pyperformance port). """ -from pprint import PrettyPrinter import pyperf +from pprint import PrettyPrinter -printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 +printable = [('string', (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 p = PrettyPrinter() -def benchmark_pprint(runner): - # Support CPython before 3.10 and non-CPython implementations - if hasattr(p, '_safe_repr'): - runner.bench_func('pprint_safe_repr', p._safe_repr, printable, - {}, None, 0) - runner.bench_func('pprint_pformat', p.pformat, printable) - - -if __name__ == "__main__": +if __name__ == '__main__': runner = pyperf.Runner() - runner.metadata['description'] = "pprint benchmark" + runner.metadata['description'] = 'pprint benchmark' - args = runner.parse_args() - benchmark_pprint(runner) + if hasattr(p, '_safe_repr'): + runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) + runner.bench_func('pformat', p.pformat, printable) From 625f58fecd5fa808323323901f4635a8458b0830 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Thu, 7 Jul 2022 23:55:58 +0300 Subject: [PATCH 9/9] Return accidentally removed full test names --- .../data-files/benchmarks/bm_pprint/run_benchmark.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py index a3ae55f8..124976d4 100644 --- a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -18,5 +18,6 @@ runner.metadata['description'] = 'pprint benchmark' if hasattr(p, '_safe_repr'): - runner.bench_func('_safe_repr', p._safe_repr, printable, {}, None, 0) - runner.bench_func('pformat', p.pformat, printable) + runner.bench_func('pprint_safe_repr', p._safe_repr, + printable, {}, None, 0) + runner.bench_func('pprint_pformat', p.pformat, printable)