Speed of Python vs. Perl

Tim Hammerquist tim at degree.ath.cx
Thu Jan 11 03:54:17 EST 2001


Michael P. Soulier <msoulier at storm.ca> wrote:
> In article <t5eojolijv1e58 at corp.supernews.com>, AndroidMonkey wrote:
> >In the last Maximum Linux magazine, there was an article about using Perl
> >for a car MP3 player.  It got me wondering - What's the speed of Python like
> >compared to Perl? I've never used Perl before, so I hope someone could
> >answer my question here. Thanks  -vm

The biggest effective difference between the two is how the programmer
interacts with it.  Perl tends to have a longer learning curve, which
many (maybe not in _this_ NG) consider worth it.  =)  This still doesn't
make either better nor more robust than the other.

> [msoulier at lupus test]$ time ./bench.pl
> 
> real    0m2.006s
> user    0m1.950s
> sys     0m0.030s
> 
> [msoulier at lupus test]$ time ./bench.py
> 
> real    0m0.558s
> user    0m0.440s
> sys     0m0.050s

How much of these times is the startup time for the interpreters?
Python has a profiler, and the Standard Perl Dist. includes the
Benchmark module for this purpose.  This would give you a more accurate
picture of where the processor spends its time.

>     I ran these a few times to ensure that the perl and python interpreters
> were in the disk cache.

Still doesn't cover interpreter startup time, but commonly overlooked.

>     They are comparable in any case, but it really depends on what you use
> them for. It's not really much of a relevant question anyway. If one performs
> worse than the other, it's still fine if it performs fast enough for your
> purposes. 
>     Besides, if you want "real" performance, use C. ;-)

I'm glad you mentioned this.  If speed is _that_ important for any given
program, consider if it should be written in a lower-level language such
as C/C++, or just cut out the processor intensive section, write and
compile in C, and link in.  Both Perl and Python support this.

-- 
-Tim Hammerquist <timmy at cpan.org>
I am opposed to millionaires, but it would
be dangerous to offer me the position.
	-- Mark Twain



More information about the Python-list mailing list