Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > loop in python

Reply
Thread Tools

loop in python

 
 
Rick Wotnaz
Guest
Posts: n/a
 
      08-22-2005
km <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

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

--
rzed
 
Reply With Quote
 
 
 
 
bruno modulix
Guest
Posts: n/a
 
      08-22-2005
km wrote:
> 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....


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
 
 
 
Daniel Dittmar
Guest
Posts: n/a
 
      08-22-2005
km wrote:
> 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
 
Reply With Quote
 
D H
Guest
Posts: n/a
 
      08-22-2005
km wrote:
> 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.
 
Reply With Quote
 
Randy Bush
Guest
Posts: n/a
 
      08-23-2005
computers are cheap. i am expensive. give me clear and maintainable
code every time.

randy

 
Reply With Quote
 
Gregory Bond
Guest
Posts: n/a
 
      08-23-2005
km wrote:

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

 
Reply With Quote
 
km
Guest
Posts: n/a
 
      08-23-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments