Support unavailable
Please try again later

Python is Faster Than FORTRAN

by Mike Müller for EuroPython 2012

Many people may think that Python is slow because it is compiled to byte code. This presentation shows that Python can be fast even for computational intensive applications. In the example presented here, Python competes with FORTRAN, a programming languages renowned for its performance and aggressively optimizing compilers.

Python offers powerful data structures such as sets that make writing efficient algorithms extremely simple. FORTRAN on the other hand, has much less in such support. For the given example, it takes considerably more programming in FORTRAN than in Python to achieve similar execution times for large data sizes. The comparison of program run times and lines of code, which can be roughly translated into development effort, shows that Python can actually be faster than FORTRAN under many circumstances typically found in real life.

Video

Comments

  1. Gravatar
    This is a very unfair title and study. Python is known to be VERY slow in most of the applications (see here http://benchmarksgame.alioth.debian.org/). You might of course find some example that it can be faster compared to Fortran or any other language. Also, you falsely argue that since people do not know about how to code efficiently then Python is faster than Fortran.
  2. Gravatar
    The presentation slides do not seem to have been made available, which makes it difficult to understand whether the FORTRAN program has been deliberately written in a bad way.

    "FORTRAN CODE - need to read once just to count the lines"

    Why can't you use allocatable arrays?

    My guess is that you could easily make your point that a "batteries included" scripting language like Python has more efficient data structures built-in without making worse-case assumptions about the FORTRAN code.
  3. Gravatar
    Badly written Fortran will always be slower.

    If you write a Fortran program that takes 3 hours to read through and intersect a pair of million line files you are seriously bad at at Fortran :)

    And what's with the obsession with number of lines of code...

    The Python program is 8 lines long because it makes use of included functions that do most of the work.

    Libraries also exist for Fortran and are commonly used by Fortran programmers to achieve the same effect. The Fortran program presented here is very poor, all that unnecessary double opening of files etc, and it took the author more than half a day, probably because he doesn't know Fortran very well.

    Other comparisons like comparing the eighteen year old Fortran-95 with modern Python don't stack up well and including error trapping code in the Fortran version and leaving it out of the Python is also quite disingeneous.

    If you really think code should be measured in number of lines, then in modern Fortran using commonly available libraries this problem reduces to three lines, one to open both files (yes, we have multiple file open!), one to find the intersection, and one to print the results.

    I'm not a Python or Fortran fanboy, they are both great tools, but you have to know how to use them.

New comment

Language
EN
Duration
45 minutes (inc Q&A)

Tagged as

performance Algorithms case-study
Our Sponsors
Spotify
Python Experts
SSL Matrix
Wanna sponsor?