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

MRAB python at mrabarnett.plus.com
Mon Mar 7 21:47:06 EST 2016


On 2016-03-08 01:33, BartC wrote:
> On 08/03/2016 01:23, Chris Angelico wrote:
>> On Tue, Mar 8, 2016 at 12:00 PM, BartC <bc at freeuk.com> wrote:
>>> Yes of course it does. As does 'being slow'. Take another microbenchmark:
>>>
>>> def whiletest():
>>> |   i=0
>>> |   while i<=100000000:
>>> |   |   i+=1
>>>
>>> whiletest()
>>>
>>> Python 2.7:  8.4 seconds
>>> Python 3.1: 12.5 seconds
>>> Python 3.4: 18.0 seconds
>>>
>>> Even if you don't care about speed, you must admit that there appears to be
>>> something peculiar going on here: why would 3.4 take more than twice as long
>>> as 2.7? What do they keep doing to 3.x to cripple it on each new version?
>>
>> How do your benchmarks compare on this code:
>>
>> pass
>
> Let me ask you a follow-on question first: how slow does a new Python
> version have to be before even you would take notice?
>
> Compared with 2.7, 3.4 above is spending nearly an extra ten seconds
> doing .... what? I can't understand why someone just wouldn't care.
>
Part of it will be that Python 2 has 2 integer types: 'int' (fixed 
length) and 'long' (variable length).

Originally, 'int' addition could overflow, but it was more friendly to 
promote the result to 'long' instead.

Python 3 dropped 'int' and renamed 'long' to 'int'.




More information about the Python-list mailing list