Skip to content

Commit 684eafe

Browse files
authored
Add a benchmark based on python -m pprint (#222)
* Port pprint performance tests * Benchmark _safe_repr only if it exists * Rename the benchmark * Remove a spurious `cmd` variable * Move constant object to a module level * Add a description * Rename benchmark labels * Make the benchmark top-level * Return accidentally removed full test names
1 parent ac914ac commit 684eafe

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

pyperformance/data-files/benchmarks/MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pickle_dict <local:pickle>
3939
pickle_list <local:pickle>
4040
pickle_pure_python <local:pickle>
4141
pidigits <local>
42+
pprint <local>
4243
pyflate <local>
4344
python_startup <local>
4445
python_startup_no_site <local:python_startup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "pyperformance_bm_pprint"
3+
requires-python = ">=3.8"
4+
dependencies = ["pyperf"]
5+
urls = {repository = "https://github.com/python/pyperformance"}
6+
dynamic = ["version"]
7+
8+
[tool.pyperformance]
9+
name = "pprint"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Test the performance of pprint.PrettyPrinter.
2+
3+
This benchmark was available as `python -m pprint` until Python 3.12.
4+
5+
Authors: Fred Drake (original), Oleg Iarygin (pyperformance port).
6+
"""
7+
8+
import pyperf
9+
from pprint import PrettyPrinter
10+
11+
12+
printable = [('string', (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000
13+
p = PrettyPrinter()
14+
15+
16+
if __name__ == '__main__':
17+
runner = pyperf.Runner()
18+
runner.metadata['description'] = 'pprint benchmark'
19+
20+
if hasattr(p, '_safe_repr'):
21+
runner.bench_func('pprint_safe_repr', p._safe_repr,
22+
printable, {}, None, 0)
23+
runner.bench_func('pprint_pformat', p.pformat, printable)

0 commit comments

Comments
 (0)