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.
"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.
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.