Python 2 times slower than Perl

Bengt Richter bokr at accessone.com
Wed Jul 18 01:15:48 EDT 2001


On Tue, 17 Jul 2001 17:17:09 -0500, Skip Montanaro <skip at pobox.com> wrote:

>
>    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.
>
Well rare, but not always dumb, I think. If you're only using a constant in one
place that happens to be in a loop, and the clearest way to express it is
as a constant expresssion, you do it that way when you know it's going to be
folded. E.g., compare (5280.0/60.0*60.0) vs 1.4666667 -- which would you feel
surer about, reviewing the code, given the same comment saying mph->fps?

Of course, with Python it would be dumb not to move it out of the loop, if
you could save significant execution time.



More information about the Python-list mailing list