Python 2 times slower than Perl

Roman Suzi rnd at onego.ru
Wed Jul 18 16:45:02 EDT 2001


On Wed, 18 Jul 2001, John J. Lee wrote:

>On 18 Jul 2001, Johann Hibschman wrote:
>[...]
>> cc -O2       0.28
>> cc           0.62
>> ocamlopt     1.26   (compiled)
>> ocaml        9.42   (interpreted)
>> perl        28.9
>> python      66.8
>>
>> Hm.  I'm beginning to wonder if I compiled python with -O2 or not.
>> Plus, I'm becoming more and more fond of ocaml.

I have
65.67user 0.07system 1:05.90elapsed 99%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (253major+163minor)pagefaults 0swaps
with Python 2.1.1c1 (on AMD K6-225)

Other Python versions on the same machine:
$ time python1.5 tst.py
10000000.500000 6.250000

61.95user 0.03system 1:02.43elapsed 99%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (345major+76minor)pagefaults 0swaps
$ time python2.0 tst.py
10000000.500000 6.250000

61.68user 0.03system 1:02.40elapsed 98%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (419major+95minor)pagefaults 0swaps

$ time python2.1 tst.py
10000000.500000 6.250000

63.72user 0.02system 1:04.00elapsed 99%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (290major+108minor)pagefaults 0swaps

(these results are not strictly correct, because I have not done reruns to
eliminate startup times differences properly.

>>
>> The python function I used was the basic
>>
>> def test ():
>>     i = 2.5
>>     j = 2.5
>>     while i < 1e7:
>>         j = 2.5 * 2.5
>>>         i = i + 1.0
>>     print "%f %f\n" % (i, j)
>>
>> if __name__ == '__main__':
>>     test ()
>
>When do you ever write Python code that does this kind of thing??  For
>example, if you're doing lots of fp work, don't you use Numeric?
>
>Must try OCaml, though (and Haskell)...

That is my observation too after I saw language shootout results.
(URL appeared here many times).

But in my applications speed is not the main virtue. The top thing is
express logic in a plain language and this is Python great at.

However, my collegues noticed that Python is too slow to be Squid
redirector (to stop ads) while Perl is great at the same task (because
Perl was designed for such application).

This doesn't make Python worse! If you rewrite the test above in Assembly,
you will get it even faster than in C, but does the effort spent worth it?

That is why I do not understand why Java is so popular:  it is not large
enough improvement over C/C++ in terms of source readability but still
poses serious overhead in execution speed... I have the feeling it stalled
at the middle between C++ and Python...

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Wednesday, July 18, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Hard work never killed anyone, but why chance it?" _/





More information about the Python-list mailing list