Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 10, 2024

@vstinner
Copy link
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
37 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant