Python 2 times slower than Perl

Roman Suzi rnd at onego.ru
Wed Jul 18 04:07:37 EDT 2001


On 18 Jul 2001, Xu, C.S. wrote:

> Thanks for all comments. Now I revised my stupid testing
> python script to adopt both a func (save original 38 seconds
> to 28 seconds) and a for loop (save original 38 seconds to
> 21 seconds), I got 16.0 seconds, which is pretty comparable
> to perl's 15.4 seconds.
> 
> The revised stupid testing py is:
> 
> #!/usr/bin/env python
> def f():
>         for i in xrange(2.5, 1e7, 1.):
>                 j = 2.5 * 2.5
>         print i, j
> f()
> 
> 
> Interesting is for perl: On the same PII 450 MHz, "for" loop
> in stead of "while" loop increase about 10% speed, but on another
> PIII 1GHz, "for" slowes down speed by 30% (from 8 seconds of
> "while" to 10.6 seconds of "for"). Only computers themselves
> can understand, :-(

>>> def f():
...         for i in xrange(2.5, 1e7, 1.):
...                 j = 2.5 * 2.5
...         print i, j
...
>>> f()
9999999 6.25
>>> import profile
>>> profile.run("f()")
9999999 6.25
         3 function calls in 11.680 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1   11.630   11.630   11.630   11.630 <stdin>:1(f)
        1    0.000    0.000   11.630   11.630 <string>:1(?)
        1    0.050    0.050   11.680   11.680 profile:0(f())
        0    0.000             0.000          profile:0(profiler)



How do you measure?

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list