Published in News

Economists should learn C++

by on09 July 2014

Stay off the Java

Two economists, S. Boragan Aruoba of the University of Maryland and Jesus Fernandez-Villaverde of the University of Pennsylvania, say that the best programming language for economists is C++. In a National Bureau of Economic Research paper with the catchy title A Comparison of Programming Languages in Economics the pair tested a handful of programming languages commonly used by economists to solve a well-known economic model.

What they thought would be a good test was the problem of stochastic neoclassical growth model. In economics it is not stochastic it is fairly pointless. Using an algorithm which was representative of the computing economists need to do, the pair coded the same problem in three compiled languages (C++, Fortran, Java) using a variety of compilers and five scripting languages (Julia, Python, Matlab, Mathematica, R) and ran the programs on two platforms, Windows and Mac. The languages were then evaluated based on their code execution time.

While Fortran is a popular for economists, it was the C++ that ran the fastest on both Mac and Windows. The elapsed time for C++ compiled with GCC was 0.73 seconds on the Mac, while it was 0.76 seconds for C++ compiled with Visual C++ on Windows. Fortran was a close second on both platforms; execution time on the Mac for Fortran compiled with GCC was 0.76 seconds, while on Windows, it was 0.81 seconds for Intel Fortran. The only other language to come close was Java, which had executions times of 1.95 seconds on Mac and 1.59 seconds on Windows, still twice as slow as C++ and Fortran.

Scripting languages fared worse than compiled languages. Julia did the best, coming in close to Java, about twice as slow as C++. Matlab was about 10-times slower than C++ on both Mac and Windows, while Python code ranged from being about 40-times slower than C++ on both Mac and Windows (for Pypy) to well over 200-times slower (CPython) on the Mac. R ranged from 500 to 700-times slower, while Mathematica did the worst, being 800-times slower than C++ on the Mac.

Boragan Aruoba and Fernandez-Villaverde did not attempt to use special features of each language to optimise the code, instead opting for similar implementations across the languages as a way to control for programmer skill and because it would make comparison difficult.

Rate this item
(0 votes)