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

BartC bc at freeuk.com
Mon Mar 7 08:25:38 EST 2016


On 07/03/2016 12:19, Fabien wrote:
> On 03/07/2016 12:38 PM, BartC wrote:
>>
>> (Although competing with CPython is too easy. PyPy is more of a problem.
>> With the Jpeg benchmark I mentioned, I can beat PyPy up to 6Mpix, but
>> then PyPy starts to get faster. At 80Mpix, PyPy is 60% faster.)
>
> Just out of curiosity: are you also competing against numpy/scipy?

No, I only compare basic language functions. I understand that Python 
depends on complex built-in functions, and external libraries such as 
numpy, for it to be used viably. But I'm also interested in using such 
languages directly.

Take the jpeg benchmark. Of course both Python and my language are 
hopelessly slow and impractical compared with a C implementation, but 
this is still a useful test (and in fact the interpreted version was 
used to more easily develop a streamlined decoder that was then 
back-ported to C, doubling its speed).

(The Python version of that program is here:
http://pastebin.com/cHx3UhQb. It should work with any Python.)

For example, suppose you wanted to do crude animation by loading a 
series of small 640x480 images. Loading such an image gives you the 
following frame rates, excluding the extra overheads of displaying the 
results:

Python 2.7:    0.33 fps
Python 3.4:    0.25 fps
PyPy:          0.55 fps (don't known what version)
Mine:          3.77 fps

You can't really call the first three animated (more like a slide show), 
but 4 fps just about cuts it!

Sometimes pushing an interpreted language a bit further can be useful 
(hence the existence of the PyPy project).

-- 
Bartc



More information about the Python-list mailing list