Skip to content

gh-125196: Use PyUnicodeWriter for repr(tuple) - #125242

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:writer_tuple
Oct 10, 2024
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:writer_tuple

Conversation

@vstinner

@vstinner vstinner commented Oct 10, 2024 •

Copy link
Copy Markdown
Member
@vstinner

Copy link
Copy Markdown
Member Author

Benchmark:

import pyperf
runner = pyperf.Runner()

runner.bench_func('repr(())', repr, ())
runner.bench_func("repr(('abc',))", repr, ('abc',))
runner.bench_func('repr((1,2,3))', repr, (1, 2, 3))
tuple4 = ('abcdef',) * 10
runner.bench_func('repr(tuple4)', repr, tuple4)
tuple5 = ('abcdef',) * 50
runner.bench_func('repr(tuple5)', repr, tuple5)

Result on Python built with ./configure CC=clang LD=clang --with-lto=thin, CPU isolation, benchmark run with --rigorous:

+----------------+---------+-----------------------+
| Benchmark      | main    | change                |
+================+=========+=======================+
| repr(())       | 55.0 ns | 55.9 ns: 1.02x slower |
+----------------+---------+-----------------------+
| repr(('abc',)) | 210 ns  | 239 ns: 1.14x slower  |
+----------------+---------+-----------------------+
| repr((1,2,3))  | 290 ns  | 189 ns: 1.54x faster  |
+----------------+---------+-----------------------+
| repr(tuple4)   | 850 ns  | 870 ns: 1.02x slower  |
+----------------+---------+-----------------------+
| Geometric mean | (ref)   | 1.05x faster          |
+----------------+---------+-----------------------+

Benchmark hidden because not significant (1): repr(tuple5)
@vstinner
vstinner enabled auto-merge (squash) October 10, 2024 10:13
@vstinner
vstinner merged commit 82dfdc3 into python:main Oct 10, 2024
@vstinner
vstinner deleted the writer_tuple branch October 10, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant