Speed of Python vs. Perl
Michael P. Soulier
msoulier at storm.ca
Sun Jan 7 14:52:22 EST 2001
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
It really depends on what you're doing. Each language has its advantages.
Implementation matters a lot too. For example:
[msoulier at lupus test]$ cat bench.pl
#!/usr/bin/perl
%hash = ();
for ($i = 0; $i < 100000; ++$i) {
$hash{$i} = 1;
}
This is a typical perl implementation of a loop. The use of the for loop
and its integer operations though, don't help the performance. If we instead
use Python's range function, we'll probably get better performance.
[msoulier at lupus test]$ cat bench.py
#!/usr/bin/python
dict = {}
for i in range(100000):
dict[i] = 1
And we do...
[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
I ran these a few times to ensure that the perl and python interpreters
were in the disk cache.
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. ;-)
Mike
--
Michael P. Soulier <msoulier at storm.ca>
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort." -Harley Hahn, A Student's Guide to UNIX
PGP Public Key: http://24.43.42.96/email.phtml
More information about the Python-list
mailing list