Speed of Python vs. Perl 
Author Message
 Speed of Python vs. Perl

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


Thu, 26 Jun 2003 02:23:25 GMT  
 Speed of Python vs. Perl

Quote:

> 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

From what I've seen and heard, if you must have an
answer, it's probably that perl may have a slight
edge.  But realistically, the question is loaded,
since python and perl don't often do things in the
same way.

--
David Allen
http://opop.nols.com/
----------------------------------------
People are like onions -- you cut them up, and they make you cry.



Thu, 26 Jun 2003 03:22:27 GMT  
 Speed of Python vs. Perl

Quote:

> 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

What's the relationship between performance and suitability for a car
MP3 player? I'd think even something as slow as JavaScript would be
applicable for that task. There is already a car MP3 player written in
Python! The company that did it was bought by S3.

http://www2.linuxjournal.com/lj-issues/issue63/3420.html

 Paul



Thu, 26 Jun 2003 03:43:06 GMT  
 Speed of Python vs. Perl
On Sat, 6 Jan 2001 13:23:25 -0500, AndroidMonkey

Quote:

>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

I haven't read the magazine you refer to, but either Python or Perl would be
fast enough to control an mp3 player, including displaying the state of
playback, manipulating playlists, and accepting user input.

In Python, you might use Gtk, Tkinter, or curses to display a GUI interface,
popen2 or a custom extension module to control the underlying mp3 decoder,
and custom classes class for playlists and tracks.  I am not familiar with
the format of mp3 tags, but there have been several threads in the newsgroup
about them recently.  I imagine that a nicely written module for getting title/
artist/etc information out of the files must exist by now.

You won't actually write an mp3 decoder in perl or python, it will be written
in C, possibly with portions in assembler for the lowest CPU consumption.

Jeff



Thu, 26 Jun 2003 04:06:12 GMT  
 Speed of Python vs. Perl

| It got me wondering - What's the speed of Python like compared to
| Perl?

they're pretty much the same speed.

  -- erno



Thu, 26 Jun 2003 05:17:36 GMT  
 Speed of Python vs. Perl

Quote:

>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:


#!/usr/bin/perl

%hash = ();
for ($i = 0; $i < 100000; ++$i) {
    $hash{$i} = 1;

Quote:
}

    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.


#!/usr/bin/python

dict = {}
for i in range(100000):
    dict[i] = 1

    And we do...


real    0m2.006s
user    0m1.950s
sys     0m0.030s


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

--

"...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



Fri, 27 Jun 2003 03:52:22 GMT  
 Speed of Python vs. Perl
[David Allen]

Quote:
> From what I've seen and heard, if you must have an answer, it's
> probably that perl may have a slight edge.

It depends very much on what you're doing (and how you're doing it <wink>).

Quote:
> But realistically, the question is loaded, since python and
> perl don't often do things in the same way.

That's for sure.  Over the past week, several wrestled (behind the scenes)
with the relatively poor speed of f.readline() in Python (as compared to
"<f>" in scalar context in Perl).  Turns out that the single biggest
contributor to the difference is that Python reads in a threadsafe way while
Perl doesn't:  Python spends over half its time in system stream
locking/unlocking routines called by threadsafe system getc() (and friends).
Now that we know that, we were able to make large improvements (which will
be in Python 2.1) -- but it will never be as fast as thread-unsafe input.

it's-more-fun-to-use-python-than-to-implement-it<wink>-ly y'rs  - tim



Fri, 27 Jun 2003 14:29:15 GMT  
 Speed of Python vs. Perl

Quote:

> >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.

Quote:

> real    0m2.006s
> user    0m1.950s
> sys     0m0.030s


> 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.

Quote:
>     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.

Quote:
>     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.

--

I am opposed to millionaires, but it would
be dangerous to offer me the position.
        -- Mark Twain



Mon, 30 Jun 2003 16:54:17 GMT  
 Speed of Python vs. Perl
[Michael P. Soulier]

Quote:

>> real    0m2.006s
>> user    0m1.950s
>> sys     0m0.030s


>> real    0m0.558s
>> user    0m0.440s
>> sys     0m0.050s

[Tim Hammerquist]

Quote:
> 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.

Python generally suffers much larger startup time than Perl.  Indeed, on my
box, I can clearly see the difference between:

python -c "print 'hi'"

and

perl -e "print 'hi'"

by eyeball (the former takes a noticeable fraction of a second; the latter
appears instantaneous).  The reasons for Python's relative startup sloth
have been discussed here often; a big one is that Python runs around looking
for Python files (like site.py and sitecustomize.py) at startup, and
typically does a big pile of failing fstats while failing to find those
files along the PYTHONPATH.

Despite that, Python is typically faster overall for me than is Perl.  Then
again, the things I typically do may not be typical ...

has-trouble-spelling-"web"-let-along-programming-it-ly y'rs  - tim



Mon, 30 Jun 2003 17:26:10 GMT  
 Speed of Python vs. Perl

Quote:
> [Michael P. Soulier]

> >> real    0m2.006s
> >> user    0m1.950s
> >> sys     0m0.030s


> >> real    0m0.558s
> >> user    0m0.440s
> >> sys     0m0.050s

> [Tim Hammerquist]
> > 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.

> Python generally suffers much larger startup time than Perl.  Indeed, on
my
> box, I can clearly see the difference between:

> python -c "print 'hi'"

> and

> perl -e "print 'hi'"

> by eyeball (the former takes a noticeable fraction of a second; the latter
> appears instantaneous).  The reasons for Python's relative startup sloth
> have been discussed here often; a big one is that Python runs around
looking
> for Python files (like site.py and sitecustomize.py) at startup, and
> typically does a big pile of failing fstats while failing to find those
> files along the PYTHONPATH.

> Despite that, Python is typically faster overall for me than is Perl.
Then
> again, the things I typically do may not be typical ...

> has-trouble-spelling-"web"-let-along-programming-it-ly y'rs  - tim

Would it be worth putting an optimization in so that the required paths,
etc., were pre-computed (for those who had specifically asked for such a
step)?

I can see the kinds of trouble this would lead to (same as needing to
"rehash" in some shells when new code was added to existring paths), but I
don't have any feel for how much of the startup overhead could be
precomputed.

and-don't-do-it-if-it-stops-you-from-implementing-nested-scopes-ly y'rs  -
steve



Mon, 30 Jun 2003 20:42:34 GMT  
 Speed of Python vs. Perl
On Thu, 11 Jan 2001 08:54:17 GMT,

Quote:

[snip]

>> real    0m2.006s
>> user    0m1.950s
>> sys     0m0.030s


>> 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 sat on a response to Michael's post for about an hour, and finally
decided not to send it, being sure that it would be misinterpreted as an
attempt to start a pyvspl flamewar. However, since Tim has responded
here, I figure I'll pass on my original post.

Executive summary: the numbers given above by Michael are not a good
indication of real comparative speed between similarly implemented
programs in Python and Perl.

Final disclaimer: what I write below is in no way intended to make a
claim about relative speed, usability, or karma of any language. It is
simply to clear up a minor misconception.

On Sun, 07 Jan 2001 19:52:22 GMT,

[snip]

Quote:

>#!/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.

Actually, that's not at all a typical Perl loop. The majority of Perl
gurus would infer from reading that code that the programmer is mired in
C-land and hasn't yet seen the usual Perl idioms. If iterating over
numbers is necessary, the idiom would probably be:

  for (0 .. 99999) {

But in most cases, one would iterate directly over elements, rather than
creating a list of numbers. And in this case, one might eschew the loop
altogether:


The advantages of this construct are clarity and conciseness at the
expense of a bit of speed -- the for-loop with range operator will
likely be a bit faster -- while remaining substantially faster than the
C-style loop.

Your general point -- that implementation matters and that Python
certainly has areas where it is faster than Perl -- is still quite
valid, and I do not disagree. You will find, however, that using the
range operator or the hash slice speeds up the Perl significantly.

</de-lurk>

-dlc



Mon, 30 Jun 2003 20:00:04 GMT  
 Speed of Python vs. Perl

    Tim> Indeed, on my box, I can clearly see the difference between:
    Tim> python -c "print 'hi'"
    Tim> and
    Tim> perl -e "print 'hi'"
    Tim> by eyeball (the former takes a noticeable fraction of a second; the latter
    Tim> appears instantaneous).  

Then you have better reflexes than anyone suspected or you need a better box
(I thought you had a 700+ MHz thingamabob)...  On my box (being similarly
vague), the time command shows no more than 0.04sec user time for the python
command and no more than 0.01sec user time for the perl command (even after
adding a \n to make them truly comparable ;-).

Still, the machine seems to think that Python is slower than Perl at startup
even though I can't tell...

of-course-it-could-be-a-windows-/-linux-thing-jab-jab-ly y'rs,

Skip



Mon, 30 Jun 2003 22:09:03 GMT  
 Speed of Python vs. Perl


Quote:

> 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.

Watch the C/C++ part :). In _The Practice of Programming_ by Kernighan and
Pike, a Markov chain implementation is examined using C, C++, Java, Perl
and Awk.

On WinNT, Perl completely hoses C++; on a R10000, Perl is faster than C++
using deque, and almost equal to C++ with a STL list implementation.

Unfortunately, Python wasn't included; however many very good points are
made wrt the ease of implementing the algo in each language, the vagaries of
libraries (STL on NT), and so on.

I'd recommend the book for anyone interested in a very down to earth
discussion
of efficiencies, design, choice of languages and other real world issues.



Mon, 30 Jun 2003 23:00:43 GMT  
 Speed of Python vs. Perl

Quote:

> Would it be worth putting an optimization in so that the required paths,
> etc., were pre-computed (for those who had specifically asked for such a
> step)?

if you know exactly what code you want to use, you can easily
plug in a custom importer, and put everything in a single archive
file (gordon's installer kit and pythonworks both let you do this).

Cheers /F



Mon, 30 Jun 2003 23:41:06 GMT  
 Speed of Python vs. Perl

Quote:

>     Tim> Indeed, on my box, I can clearly see the difference between:
>     Tim> python -c "print 'hi'"
>     Tim> and
>     Tim> perl -e "print 'hi'"
>     Tim> by eyeball (the former takes a noticeable fraction of a second;
the latter
>     Tim> appears instantaneous).

> Then you have better reflexes than anyone suspected or you need a better
box
> (I thought you had a 700+ MHz thingamabob)...  On my box (being similarly

...running some sort of Windows...

Quote:
> of-course-it-could-be-a-windows-/-linux-thing-jab-jab-ly y'rs,

I'm anything but a Windows-basher (as long as the market pays me for
Windows apps, that's where I'll mostly work -- I'm a grrrreedy guy),
but such aspects as the delays connected with starting something at
the commandline ARE noticeably different... Windows is VERY slow.  I
have no objective measurements of this, but subjectively it seems that
commandline apps are slower and slower with each passing Win release
(not that the GUI ones are speed demons, mind you -- nor the
daem^H^H^H^H services, etc)...

Alex



Tue, 01 Jul 2003 00:38:58 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Speed of Python vs. Perl

2. Perl speed vs. Python speed

3. Speed problems with Python vs. Perl

4. Yet another Python vs. Perl speed issue/question

5. python vs. perl speed comparisons

6. Python vs Perl: benchmarking for speed?

7. Perl vs TCL (was: Execution speed of Perl?)

8. Python Binding [Was: Re: PYTHON VS. PERL VS. TCL ]

9. Forth vs Python vs Perl

10. perl vs python vs icon

11. PYTHON VS. PERL VS. TCL

12. jredford's flames and criticism (was: PYTHON VS. PERL VS. TCL )

 

 
Powered by phpBB® Forum Software