Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Oct 15, 2024

@vstinner
Copy link
MemberAuthor

Benchmark:

import_iodefhello_world(): s=_io.StringIO() s.write('Hello ') s.write('World!') s.getvalue() deflong_strings(): s=_io.StringIO() s.write('a'*10) s.write('a'*100) s.write('a'*1000) s.getvalue() importpyperfrunner=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
MemberAuthor

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

@vstinnervstinner deleted the writer_stringio branch October 25, 2024 09:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@vstinner