Perl code 37 times quickly than Python code??

Tim Peters tim.one at home.com
Tue Jan 15 20:04:00 EST 2002


[Toni Gaya]
> ...
> Why a example as simple as that runs many times quickly in perl than
> python? it doesn't have explication. Two programs syntax are clear and
> simple....

An earler poster already explained it:  your Perl code had a common bug.
Vrbls are global by default in Perl, and you neglected to use either local()
or my() on the $i in Ramp and the $i in main.  As a result, they're the same
thing, and your Ramp function is called only once instead of the 100 times
you thought it was called.  If you don't follow this, put a print statement
at the top of Ramp, and then print $i at various places too to see how it
gets screwed up.

Since your Python code did call Ramp 100 times, it's doing 100x more work
than the Perl code.  Therefore the real mystery is why your Perl code was
*only* 37 times faster <wink>.





More information about the Python-list mailing list