Friday, 17 April 2015

Aruoba/Fernández-Villaverde: Comparison of Programming Languages in Economics

http://economics.sas.upenn.edu/~jesusfv/comparison_languages.pdf

We solve the stochastic neoclassical growth model, the workhorse of modern macroeconomics, using C++11,Fortran 2008, Java, Julia, Python, Matlab, Mathematica, and R. We implement the same algorithm, value function iteration with grid search, in each of the languages. We report the execution times of the codes in a Mac and in a Windows computer and comment on the strength and weakness of each language



Our first result is that C++ and Fortran still maintain a considerable speed advantage with respect to all other alternatives. For example, Java is between 2.10 and 2.69 times slower than C++, Matlab around 10 times slower, and the Pypy implementation of Python around 48 times slower.




Second, C++ compilers have advanced enough that, contrary to the situation in the 1990s, C++ code runs slightly faster (5-7 percent) than Fortran code. The many other strengths of C++ in terms of capabilities (full object orientation, template meta-programming, lambda functions, large user base) make it an attractive language for graduate students to learn. On the other hand, Fortran is simple and compact ñand, thus, relatively easy to learn ñand it can take advantage of large amounts of legacy code. Third, even for our very simple code, there are noticeable differences among compilers. We Önd speed improvements of more than 100 percent between different executables of the same underlying code (and using equivalent compilation flags). While the open-source GCC compilers are superior in a Mac/Unix/Linux environment (for which they have been explicitly developed) to the Intel compilers, GCC compilers do less well in a Windows machine.



Fourth, Java is between 2.2 to 2.69 times slower than C++. This difference in speed plus Javaís issues with áoating point arithmetic in high-performance scientific computation suggests that there is no obvious advantage for choosing Java over C++ unless portability across platforms or the wide availability of Java programmers is an important factor.




In the Pypy implementation, the Python code runs around 44-45 times slower than in C++. In the traditional implementation of Python (often called CPython), the code runs between 155 and 269 times slower than in C++. Other benchmarks have also found similar results. For example, the Computer Languages Benchmark Game Önds many examples where Python is over 100 times slower then C++.




R runs between 475 to 491 times slower than C++, although the performance improves somewhat (to between 243 and 281 times slower) if the R code is compiled using the R compiler package. This poor performance is well-understood in the R community and it is due, in part, to some choices in the original design of R back in the 1990s, when nobody could have forecasted its future success

No comments:

Post a Comment