How Fast Does Python Run?

Thomas Wouters thomas at xs4all.net
Sat Jun 17 06:00:03 EDT 2000


On Sat, Jun 17, 2000 at 05:24:13AM +0000, Aahz Maruch wrote:

> >And python will get faster.  There is no intrinsic reason for perl
> >to be faster than python; it's just been around longer and has been
> >optimized more.

> Your first sentence is true.  Your second sentence is false.  Perl has
> platform-specific hacks that make it faster; it's extremely unlikely
> that Python will ever go the non-portable route.

Also, Perl has syntax and semantics specifically targeted towards execution
speed, which creates a lot of room for optimization. This is most obvious in
platform-dependant areas, like the tricks used to get file-io as fast as
possible, but becomes painfully obvious if you start looking at optimizing
Python. Because Python does *not* have special exceptions intended to
execute the code faster, except for the docstrings disappearing when you use
double optimization (-OO). You can probably speed up Python quite a bit if
you concentrate on the common task and do not mind fawlty or flawed results
for the little used features.

Fortunately (in my opinion), that isn't the Python Way. There is still room
for improvement without losing accuracy and simplicity (of Python) but that
*will* cost, in simplicity-of-CPython: The current optimization (which
translates 'load_name' opcodes into 'load_global' or 'load_fast' depending
on wether they seem to be local or global) is a good example: The actual
added code is not that large or complicated, but when you start adding new
features, you have to keep those 20-odd lines of code in mind, or you'll
screw it up. Add 10 more of those 'performance hacks' and adding to CPython
can become a real pain.

Also, the load_fast-translation-cycle is skipped if the code block has a
'from module import *' or 'exec' statement in it, because the
compiler/optimizer does not know what names it imports, and hence not what
names will be actually local when the code executes.

Optimized-Python-contradicts-'simplicitly'-both-ways-ly y'rs,

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list