diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index 36992db1..43489311 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -39,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_pprint/pyproject.toml b/pyperformance/data-files/benchmarks/bm_pprint/pyproject.toml new file mode 100644 index 00000000..b0b1842f --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pprint/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "pyperformance_bm_pprint" +requires-python = ">=3.8" +dependencies = ["pyperf"] +urls = {repository = "https://github.com/python/pyperformance"} +dynamic = ["version"] + +[tool.pyperformance] +name = "pprint" diff --git a/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py new file mode 100644 index 00000000..124976d4 --- /dev/null +++ b/pyperformance/data-files/benchmarks/bm_pprint/run_benchmark.py @@ -0,0 +1,23 @@ +"""Test the performance of pprint.PrettyPrinter. + +This benchmark was available as `python -m pprint` until Python 3.12. + +Authors: Fred Drake (original), Oleg Iarygin (pyperformance port). +""" + +import pyperf +from pprint import PrettyPrinter + + +printable = [('string', (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 +p = PrettyPrinter() + + +if __name__ == '__main__': + runner = pyperf.Runner() + runner.metadata['description'] = 'pprint benchmark' + + 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)