Python 2 times slower than Perl

Gilles Lenfant glenfant.nospam at bigfoot.com
Wed Jul 18 07:35:11 EDT 2001


You can optimize this:

# "No loop verson"
i = 1e7
j = 2.5 * 2.5
print i, j

Has the same effect and is much faster 8-))

Seriously, compare 2 languages with really useful features (Genrate PDF
report, extract XML data...).
You can find useless stuffs that run much faster in Python than in Perl.

c = [0,1,2,3,4,5,6,7,8,9,10,11,12]
for i in xrange(100000):
  d=filter(lambda x : x>5, c)


"Xu, C.S." <xucs007 at yahoo.com> a écrit dans le message news:
8f41cfd.0107171238.6ff33b9b at posting.google.com...
> I just compared the speed of Python, Perl, Java, C
> to do simple numerical calculations. Python is the
> slowest: took 150 times of time than C, Perl about
> 60 times, Java is 4.5 times.
>
> The source code of Python is: (Other source are
> similar, all use while loop):
>
> #!/usr/bin/env python
> i = 2.5;
> while i < 1e7:
>         j = 2.5 * 2.5
>         i += 1
> print i, j
>
> The `time` results on my PII 450M is:
> python script: 37.93u 0.03s 0:38.03 99.8%
> perl script: 15.36u 0.03s 0:15.42 99.8%
> java compiled: 1.07u 0.10s 0:01.20 97.5%
> C compiled: 0.24u 0.01s 0:00.25 100.0%
>
> Can anybody explain why Python is always about 1 time
> slower than Perl?
>
> Regards,





More information about the Python-list mailing list