Python 2 times slower than Perl
skip at pobox.com
Wed Jul 18 00:17:09 CEST 2001
Christopher> I can't speak for Perl, but Python definately does not
Christopher> evaluate the expression at compile time. This is a problem
Christopher> I've had with Python. I wish that when given the -O option
Christopher> the compiler would do constant subexpression elimination.
It's rare in normal Python code to actually see a constant expression
computed inside a loop. Fortunately, it would appear most folks aren't that
dumb, so while you can take steps to eliminate them, there aren't generally
going to be very many to eliminate.
Experiments have been performed in this area.
* I once wrote a peephole optimizer that would precompute expressions like
The biggest boost I saw was on complex arithmetic because complex
constants aren't stored as constants at all, but as arithmetic
* Python2C may also do some of this:
* The bytecode hacks might as well (sorry no URL, check Parnassus)
* Some versions of freeze used to apply a number of peephole techniques
* Finally, Armin Rigo doing some very interesting things with compiling
Skip Montanaro (skip at pobox.com)
More information about the Python-list