Pyhon 2.x or 3.x, which is faster?

alister alister.ware at ntlworld.com
Sat Mar 12 05:06:36 EST 2016


On Fri, 11 Mar 2016 22:24:45 +0000, 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?

because the "workarround" is not a workarround it is the correct way to 
do it
the code above is a workarround for somone who does not know the pythonic 
method to do this

S= "*"*10000000



-- 
A little kid went up to Santa and asked him, "Santa, you know when I'm bad
right?"  And Santa says, "Yes, I do."  The little kid then asks, "And you
know when I'm sleeping?" To which Santa replies, "Every minute." So the
little kid then says, "Well, if you know when I'm bad and when I'm good,
then how come you don't know what I want for Christmas?"



More information about the Python-list mailing list