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 in _io.StringIO #125528

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 15, 2024

@vstinner
Copy link
Member Author

Benchmark:

import _io

def hello_world():
    s = _io.StringIO()
    s.write('Hello ')
    s.write('World!')
    s.getvalue()

def long_strings():
    s = _io.StringIO()
    s.write('a' * 10)
    s.write('a' * 100)
    s.write('a' * 1000)
    s.getvalue()

import pyperf
runner = pyperf.Runner()
runner.bench_func('hello_world', hello_world)
runner.bench_func('long_strings', long_strings)

Results, Python built with gcc -O3, CPU isolation:

+----------------+--------+----------------------+
| Benchmark      | ref    | writer               |
+================+========+======================+
| hello_world    | 322 ns | 352 ns: 1.09x slower |
+----------------+--------+----------------------+
| long_strings   | 511 ns | 547 ns: 1.07x slower |
+----------------+--------+----------------------+
| Geometric mean | (ref)  | 1.08x slower         |
+----------------+--------+----------------------+

It makes StringIO slower :-(

@vstinner
Copy link
Member Author

It's slower so I don't think that it's worth it.

@vstinner vstinner closed this Oct 25, 2024
@vstinner vstinner deleted the writer_stringio branch October 25, 2024 09:12
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