| 1 |
|
| 2 |
"""Test the performance of pprint.PrettyPrinter. |
| 3 |
|
| 4 |
This benchmark was available as `python -m pprint` until Python 3.12. |
| 5 |
|
| 6 |
Authors: Fred Drake (original), Oleg Iarygin (pyperformance port). |
| 7 |
""" |
| 8 |
|
| 9 |
from time import perf_counter |
| 10 |
from pprint import PrettyPrinter |
| 11 |
|
| 12 |
|
| 13 |
printable = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100_000 |
| 14 |
p = PrettyPrinter() |
| 15 |
|
| 16 |
|
| 17 |
if __name__ == "__main__": |
| 18 |
|
| 19 |
start_p = perf_counter() |
| 20 |
for i in range(7): |
| 21 |
p.pformat(printable) |
| 22 |
stop_p = perf_counter() |
| 23 |
print("Time elapsed: ", stop_p - start_p) |