Skip to content

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