[Theory] How to speed up python code execution / pypy vs GPU

Michael Torrie torriem at gmail.com
Mon Nov 7 19:26:14 EST 2016


On 11/05/2016 11:10 AM, Mr. Wrobel wrote:
> Hi,
> 
> Some skeptics asked my why there is a reason to use Python against of 
> any other "not interpreted" languages, like objective-C. As my 
> explanation, I have answered that there is a a lot of useful APIs, 
> language is modern, has advanced objective architecture, and what is the 
> most important - it is  dynamic and support is simply great.
> 
> However the same skeptics told my that, ok we believe that it is true, 
> however the code execution is much slower than any other compiled language.
> 
> I must tell you that is the reason I started to dig into internet and 
> searching some methods to speed up python's code.

I'm reminded of the old adage, premature optimization is the root of all
evil.  Trying to find ways of speeding up Python code is interesting,
but it may be less helpful to the general cases than you think.

It's undeniable that given a particular CPU-bound algorithm implemented
in Objective C and Python that the ObjC version will finish faster.
Probably an order of magnitude faster.  But even in this situation, the
question is, does it matter?  And in almost all cases, 90% of the
execution time of a program is spent in 10% of the code.  Once you
isolate that 10%, you can bring other tools to bear, even while you use
Python. For example that critical 10% could be compiled to binary code
with Cython.  Or you may find that using a library such as numpy to do
fast linear algebra is the way to go.

Many modern tasks are actually IO-bound rather than CPU bound so Python
would be just as fast as any other language. That's why Python is
well-placed in web development where scaling involves more than simply
CPU execution time.

I don't think you will have any luck in persuading your colleagues to
replace Objective-C with Python by chasing ways of speeding up Python.
But you may be able to show them the places where Python really shines
and they may come around to the idea of using Python in certain places
more often.



More information about the Python-list mailing list