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
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
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
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 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 =
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
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
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
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
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+
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
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
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
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
14 matches
Mail list logo