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

Steven D'Aprano steve at pearwood.info
Mon Mar 7 20:34:43 EST 2016


On Tue, 8 Mar 2016 07:47 am, Chris Angelico wrote:

> You write *real world* code and then profile that. You get actual real
> programs that you actually really use, and you run those through
> timing harnesses.


Chris, I think that's exactly what BartC has done: he has a program that he
actually uses, one which processes JPG files. It's written in pure Python,
so he's not comparing the quality of C libraries, he's comparing Python
versus Python.

I haven't looked at his code, so I don't know if its a fair comparison of
Python versus Bart's Private Language. But that's not the point. Idiomatic
Python or not, "best practice" production level code or not, it is a fair
comparison of Python 2 versus Python 3, or CPython versus PyPy, because
it's the same Python code being run each time.

Could Bart's code be improved for production use? Almost certainly. I'm sure
that by using a C image processing library, like pillow, it would be ten or
a hundred times faster. If Bart were saying "Python is crap, it's too slow"
then a perfectly acceptable response would be "no, you're just misusing it,
here you want to use it as an interface to this library and let the library
do the heavy lifting". That's what Python is designed for. But that's not
what Bart is saying.

I'm impressed that pure Python code running in CPython is even *usable* for
whatever sort of image processing BartC is doing. He must be doing
something right, given that its not unusably slow.




-- 
Steven




More information about the Python-list mailing list