loop in python

R

Rick Wotnaz

Hi all,

Why is it that the implementation of empty loop so slow in
python when compared to perl ?

#i did this in python (v 1.5)
for x in xrange(1000):
print x
# this took 0.017 seconds
--------------------------
#similar code in perl (v 5.6):
for $x (0..1000)
{
print $x;
}
# this took 0.005 seconds only !!!

Is python runtime slow at all aspects when compared to perl ?
I really wonder what makes python slower than perl ?
Is there any proposal to make python faster in future versions ?

curious to know all these ...

It appears that Python is not optimized for empty loops.
 
B

bruno modulix

km said:
Hi all,

Why is it that the implementation of empty loop so slow in python when compared to perl ?

#i did this in python (v 1.5)

Python 1.5.2 was released in april 1999. Current Python version is 2.4.1.

Please consider upgrading - unless of course you just want to troll...
for x in xrange(1000):
print x

This is not an empty loop. An empty loop is
for x in xrange(1000):
pass
Is python runtime slow at all aspects when compared to perl ?

Is your question serious or are you just trolling ?
I really wonder what makes python slower than perl ?

I really wonder what makes my old P133/32mo running w98 slower that my
more recent XP1200/256mo running gentoo/linux.
Is there any proposal to make python faster in future versions ?

The future is already here....
 
D

Daniel Dittmar

km said:
Why is it that the implementation of empty loop so slow in python when compared to perl ? [...]
Is python runtime slow at all aspects when compared to perl ?
No

I really wonder what makes python slower than perl ?

It could be that the Perl compiler recognizes such a for loop and emits
special code (e.g. an integer loop variable that gets incremented).
Python creates an xrange object and then has the overhead of 1000 next()
calls.

You should benchmark other features before jumping to conclusions: calls
to functions, calls to methods, calls to inherited methods.

Others will probably chime in with arguments whether such micro
benchmarks are a useful indication of the speed a complete program at all.
Is there any proposal to make python faster in future versions ?

Yes in the general case, probably no in this specific case.


Daniel
 
D

D H

km said:
Hi all,

Why is it that the implementation of empty loop so slow in python when compared to perl ?

#i did this in python (v 1.5)
for x in xrange(1000):
print x
# this took 0.017 seconds
--------------------------
#similar code in perl (v 5.6):
for $x (0..1000)
{
print $x;
}
# this took 0.005 seconds only !!!

Is python runtime slow at all aspects when compared to perl ?
I really wonder what makes python slower than perl ?

Yeah but the python version took 2.1 less seconds to type.
Python runs as fast as Perl.
 
R

Randy Bush

computers are cheap. i am expensive. give me clear and maintainable
code every time.

randy
 
G

Gregory Bond

km said:
Is python runtime slow at all aspects when compared to perl ?

And in addition to all that everyone else has said.... most of this is
startup time. The python interpreter is a fair bit slower to start up
(i.e. does much more at startup time) than the perl one:
lenford$ time python -c "pass"

real 0m0.298s
user 0m0.030s
sys 0m0.030s
lenford$ time perl -e "0"

real 0m0.037s
user 0m0.000s
sys 0m0.000s

[on a fairly fast Solaris box]. This is mainly because much more of
python is written in python and needs to be loaded / dynamically linked
when the process starts up. On my system, python loads 14 .so files and
13 .pyc files. Perl loads 7 .so files.
 
K

km

Hi all,

Why is it that the implementation of empty loop so slow in python when compared to perl ?

#i did this in python (v 1.5)
for x in xrange(1000):
print x
# this took 0.017 seconds
--------------------------
#similar code in perl (v 5.6):
for $x (0..1000)
{
print $x;
}
# this took 0.005 seconds only !!!

Is python runtime slow at all aspects when compared to perl ?
I really wonder what makes python slower than perl ?
Is there any proposal to make python faster in future versions ?

curious to know all these ...

regards,
KM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top