A Comparison of Programming Languages in Economics..

Keynes once famously said of the desired qualities for a top economist:

The master-economist must possess a rare combination of gifts …. He must be mathematician, historian, statesman, philosopher — in some degree. He must understand symbols and speak in words. He must contemplate the particular, in terms of the general, and touch abstract and concrete in the same flight of thought. He must study the present in the light of the past for the purposes of the future. No part of man’s nature or his institutions must be entirely outside his regard. He must be purposeful and disinterested in a simultaneous mood, as aloof and incorruptible as an artist, yet sometimes as near to earth as a politician.”

We did not have computers then otherwise he would have added computer programmer to the list as well! Moreover, his quote anyways talks about things like abstract, flight of thought etc..which programmers do have. Atleast those thinking about lionking economic issues and computer programming need to surely have.

So, there is this interesting paper which compares how various programming languages fare in trying to address a common problem:

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.


C++ and Fortran are still considerably faster than any other alternative, although one needs to be careful with the choice of compiler.
2. C++ compilers have advanced enough that, contrary to the situation in the 1990s and some folk wisdom, C++ code runs slightly faster (5-7 percent) than Fortran code.
3. Julia, with its just-in-time compiler, delivers outstanding performance. Execution speed is only between 2.64 and 2.70 times the execution speed of the best C++ compiler.
4. Baseline Python was slow. Using the Pypy implementation, it runs around 44 times slower than in C++. Using the default CPython interpreter, the code runs between 155 and 269 times slower than in C++.
5. However, a relatively small rewriting of the code and the use of Numba (a just-in-time compiler for Python that uses decorators) dramatically improves Python’s performance: the decorated code runs only between 1.57 and 1.62 times slower than the best C++ executable.
6. Matlab is between 9 to 11 times slower than the best C++ executable. When combined with Mex files, though, the difference is only 1.24 to 1.64 times. 
7. R runs between 500 to 700 times slower than C++. If the code is compiled, the code is between 240 to 340 times slower.
8. Mathematica can deliver excellent speed, about four times slower than C++, but only after a considerable rewriting of the code to take advantage of the peculiarities of the  language. The baseline version our algorithm in Mathematica is much slower, even after taking advantage of Mathematica compilation.

Some could argue that our results are not surprising as they coincide with the guesses of an experienced programmer. But we regard this comment as a point of strength, not of weakness. It is a validation that our exercise was conducted under reasonably fair conditions. Our goal is not to overturn the experience of knowledgeable programmers, but to formalize such experience under well-described and explicitly controlled conditions and to report the information to others.

Phew…the life of a budding economist keeps becoming tougher..


One Response to “A Comparison of Programming Languages in Economics..”

  1. isha agarwal Says:

    Reblogged this on econ perspective and commented:
    Good post for graduate students in economics. Interesting to note that R is almost 500 to 700 times slower than C++ whereas Matlab is only 9 to 11 times slower than C++.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: