5 ms·
For your point about Python string concatenation, I believe that's what io.StringIO is for (https://docs.python.org/3/library/io.html#io.StringIO https://docs.p
by vietjtnguyen 10y ago
For your point about Python string concatenation, I believe that's what io.StringIO is for (https://docs.python.org/3/library/io.html#io.StringIO https://docs.python.org/3/library/io.html#io.StringIO).
- maxerickson 10y agoIf you are using CPython 2.4 or 2.5 or later, use the clearest code. In earlier versions using join on a list was faster, but the inplace add operation was optimized, turning the stuff about string.join being faster mostly into mythlore. https://bugs.python.org/issue980695 https://bugs.python.org/issue980695 PyPy and other implementations may do better with the join idiom though. Of course someone with code spending a lot of time on joining strings can measure which is best for their situation, but += is fine for most things.
- willvarfar 10y agohttp://pypy.org/performance.html http://pypy.org/performance.html says "String concatenation is expensive" and suggests using join() in loops. Its an old problem https://bitbucket.org/pypy/pypy/issues/1925/very-slow-string-concatenation https://bitbucket.org/pypy/pypy/issues/1925/very-slow-string... So whilst pypy is otherwise much faster than CPython, its missing of this kind of optimisation is why actually CPython can be faster for parsing my logs. I know about this because I've been bitten by it :)