Re: String concatenation performance with +=

2009-02-14 Thread Sammo
On Feb 14, 4:47 pm, Steven D'Aprano st...@pearwood.info wrote: Sammo sammo2828 at gmail.com writes: String concatenation has been optimized since 2.3, so using += should be fairly fast. This is implementation dependent and shouldn't be relied upon. It's also a fairly simple optimization

Re: String concatenation performance with +=

2009-02-14 Thread Sammo
On Feb 14, 5:33 pm, Steven D'Aprano st...@pearwood.info wrote: AFAIK, using list mutation and .join only improves performance if the .join is executed outside of the loop. Naturally. If you needlessly join over and over again, instead of delaying until the end, then you might as well do

Re: String concatenation performance with +=

2009-02-14 Thread Nick Craig-Wood
Sammo sammo2...@gmail.com wrote: String concatenation has been optimized since 2.3, so using += should be fairly fast. In my first test, I tried concatentating a 4096 byte string 1000 times in the following code, and the result was indeed very fast (12.352 ms on my machine). import

Re: String concatenation performance with +=

2009-02-14 Thread Steven D'Aprano
Nick Craig-Wood wrote: The optimized += depends on their being no other references to the string.  Strings are immutable in python.  So append must return a new string.  However the += operation was optimised to do an in-place append if and only if there are no other references to the string.

String concatenation performance with +=

2009-02-13 Thread Sammo
String concatenation has been optimized since 2.3, so using += should be fairly fast. In my first test, I tried concatentating a 4096 byte string 1000 times in the following code, and the result was indeed very fast (12.352 ms on my machine). import time t = time.time() mydata = moredata =

Re: String concatenation performance with +=

2009-02-13 Thread Benjamin Peterson
Sammo sammo2828 at gmail.com writes: String concatenation has been optimized since 2.3, so using += should be fairly fast. This is implementation dependent and shouldn't be relied upon. Note that I need to do something to mydata INSIDE the loop, so please don't tell me to append

Re: String concatenation performance with +=

2009-02-13 Thread Sammo
Okay, this is what I have tried for string concatenation: 1. Using += implemented using simple operations (12 ms) 2. Using += implemented inside a class (4000+ ms) 3. Using .join implemented using simple operations (4000+ ms) 4. Using .join implemented inside a class (4000+ ms) On Feb 14, 3:12 

Re: String concatenation performance with +=

2009-02-13 Thread Steven D'Aprano
Benjamin Peterson wrote: Sammo sammo2828 at gmail.com writes: String concatenation has been optimized since 2.3, so using += should be fairly fast. This is implementation dependent and shouldn't be relied upon. It's also a fairly simple optimization and really only applies to direct

Re: String concatenation performance with +=

2009-02-13 Thread Steven D'Aprano
Steven D'Aprano wrote: Benjamin Peterson wrote: Sammo sammo2828 at gmail.com writes: String concatenation has been optimized since 2.3, so using += should be fairly fast. This is implementation dependent and shouldn't be relied upon. It's also a fairly simple optimization and really

Re: String concatenation performance with +=

2009-02-13 Thread Steven D'Aprano
Sammo wrote: Okay, this is what I have tried for string concatenation: 1. Using += implemented using simple operations (12 ms) 2. Using += implemented inside a class (4000+ ms) 3. Using .join implemented using simple operations (4000+ ms) 4. Using .join implemented inside a class (4000+

String concatenation performance

2006-05-11 Thread Cristian.Codorean
I was just reading a Python Speed/Performance Tips article on the Python wiki http://wiki.python.org/moin/PythonSpeed/PerformanceTips and I got to the part that talks about string concatenation and that it is faster when using join instead of += because of strings being immutable. So I have tried

Re: String concatenation performance

2006-05-11 Thread Duncan Booth
Cristian.Codorean wrote: I was just reading a Python Speed/Performance Tips article on the Python wiki http://wiki.python.org/moin/PythonSpeed/PerformanceTips and I got to the part that talks about string concatenation and that it is faster when using join instead of += because of strings

Re: String concatenation performance

2006-05-11 Thread Ben Sizer
Cristian.Codorean wrote: I was just reading a Python Speed/Performance Tips article on the Python wiki http://wiki.python.org/moin/PythonSpeed/PerformanceTips and I got to the part that talks about string concatenation and that it is faster when using join instead of += because of strings

Re: String concatenation performance

2006-05-11 Thread Bruno Desthuilliers
Cristian.Codorean a écrit : I was just reading a Python Speed/Performance Tips article on the Python wiki http://wiki.python.org/moin/PythonSpeed/PerformanceTips and I got to the part that talks about string concatenation and that it is faster when using join instead of += because of strings