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 stri
Sammo 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 time
> t =
On Feb 14, 5:33 pm, Steven D'Aprano 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 string conca
On Feb 14, 4:47 pm, Steven D'Aprano wrote:
> > Sammo 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 a
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
Steven D'Aprano wrote:
> Benjamin Peterson wrote:
>
>> Sammo 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
Benjamin Peterson wrote:
> Sammo 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
object a
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:1
Sammo 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 moredata to a
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 = "A"
10 matches
Mail list logo