Comparing perl and python

François Pinard pinard at iro.umontreal.ca
Wed Feb 23 01:19:15 EST 2000


Tim Roberts <timr at probo.com> writes:

> I am disturbed by what seems to be a dramatic performance difference
> [between Perl and Python...]  Have others done such comparisons?

Just a few months ago, I was also a complete newbie, and has also been
worried by speed differences, the same as you do now, and raised the matter
on that discussion list.  Most certainly, others did before me :-).

My first attempts at writing Python were much tainted with Perl style, and
had to discover that you have to learn a few Python idioms to get more speed.
More generally, Python gives you more control than Perl on details, but
you have to be a bit more careful at details as well.  For example, Perl
has a lot of optimisation work put on regular expressions and input/output,
some say insane optimisation :-).  Python has a more relaxed implementation
of both, and we have to learn to avoid using regular expressions everywhere
and all the time, and learn to bunch input/output more than we do in Perl.
In a word, you have to learn to compensate a bit, with better algorithms.
This is usually easy, because of the gain in clarity you've already got.

This comes with experience, I guess.  This mailing list is also a very
good resource.  I do not notice speed differences as much as when I began to
write Python, but I feel I write in a more Pythonic than Perlish style now.
Speed differences might still exist, but not enough to be really bothering.
The advantages of Python, for me, overcome some inherent slowness at
times, yet my feeling is that Python speed is quite reasonable on average.
It is probably that my first experiments were lacking a bit, style-wise.

P.S. - I've now written well over 20000 lines of Python, and continuing.
I feel a bit more solid than I was initially :-).  Strangely, I'm not in
a hurry to use every feature available.  I'm quite satisfied with simplicity.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list