Speed Comparison Perl Python & C

beliavsky at aol.com beliavsky at aol.com
Mon Mar 1 19:35:32 CET 2004

Bart Nessux <bart_nessux at hotmail.com> wrote in message news:<c1t89m$a3u$1 at solaris.cc.vt.edu>...


As others pointed out, your programs mostly test the speed of I/O.
Here is a simple comparison of the speed of integer arithmetic using
Python and Fortran 95 (Compaq Visual Fortran 6.6, with full


i = 1
j = 0
while i < 100000000:
   j = j + i
   i = i + 1
print j

Fortran 95:

program add
integer*8 :: i,j
j = 0
do i=1,99999999
   j = j + i
end do
end program add

numerical result: 4999999950000000
elapsed times in seconds, using timethis.exe command on Windows XP

Python   93.4
Fortran   0.28

The Fortran program is more than 300 times faster. The benchmarks at
http://www.polyhedron.co.uk/compare/win32/f90bench_p4.html suggest
that the Fortran/Python speed gap is even larger if the Intel Fortran
compiler is used.
The speed ratio of the fastest to slowest Fortran compiler is about
two, so ANY Fortran compiler beats Python by more than two orders of
magnitude here.

The Intel Fortran compiler for Linux can be obtained free for
noncommercial use at
http://www.intel.com/software/products/compilers/flin/noncom.htm .

More information about the Python-list mailing list