Pyhon 2.x or 3.x, which is faster?
BartC
bc at freeuk.com
Sat Mar 12 05:34:46 EST 2016
On 12/03/2016 01:15, Michael Torrie wrote:
> On 03/11/2016 03:24 PM, BartC wrote:
>> On 11/03/2016 21:59, Mark Lawrence wrote:
>>> On 11/03/2016 18:57, BartC wrote:
>>
>>> def test():
>>> s=""
>>> for i in range(10000000):
>>> s+="*"
>>> print (len(s))
>>>
>>> test()
>>
>>> The minor snag that you might like to correct with your microbenchmark,
>>> which any experienced Python programmer knows, is that you *NEVER, EVER*
>>> create strings like this.
>>
>> Why not? Chris said his version runs much faster (even allowing for
>> different machines), and might have a special optimisation for it.
>>
>> And I think it can be optimised if, for example, there are no other
>> references to the string that s refers to.
>>
>> So what's wrong with trying to fix it rather that using a workaround?
>
> The act of "fixing" it, as you say, would change the semantics of the
> language in a fundamental and major way. Strings by definition are
> immutable in Python.
Yet INPLACE_ADD is a valid byte-code even when operating on strings.
--
Bartc
More information about the Python-list
mailing list