Best Programming Language for Economists is C++?

Old 2 Comments on Best Programming Language for Economists is C++? 105

A paper in the  National Bureau of Economic Research by two economists, Boragan Aruoba of the University of Maryland and Jesus Fernandez-Villaverde of the University of Pennsylvania, has concluded that C++ is the best option for doing economic calculations. They created a version of the stochastic neoclassical growth model 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. 

Compiled Results

 C++ 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 very close second  for either platform; 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 to C++ and Fortran was Java, it had executions times of 1.95 seconds on Mac and 1.59 seconds on Windows, coming in at half the speed C++ and Fortran. 

Compiler Choice Matters

While C++ and Fortran dominated the other languages in performance time, the choice of compiler really mattered. The GCC compiler ran faster than Intel compiled code on the Mac, while the opposite was true on Windows. The difference in Windows was so significant that the Intel-compiled code ran about twice as fast as GCC-compiled code on Windows for both C++ (0.90 to 1.73 seconds) and Fortran (0.81 to 1.73).

Scripting Language Results

Generally the scripting langues couldn’t come close to the compiled languages.

  •  Out of the 5, Julia did the best, coming in close to Java.
  • Matlab was about 10-times slower than C++ on both Mac and Windows.
  • 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.
  •  Mathematica did the worst, being 800-times slower than C++ on the Mac.

The authors did find, however, that the performance of scripting languages could be greatly increased by compiling parts of the code when possible. Matlab speed goes to just twice as slow as C++ when compiling into Mex (C++) files, with a similar increase found for Python with Numba.

So while the results are interesting, professional programmers have a deeper knowledge of these languages than any economist does, and could optimize the code, potentially coming up with very different results. The authors have made their code available on GitHub, if you’d like to see how the language perform when optimized. 

Regardless of the usefulness of this study, its nice to see that non-IT folk are trying to learn something new about programming, and are attempting to figure out which is the best for their application. It’d be interesting to see more studies like this in the future.

Author

Nicholas Fusco

Nick Fusco is a young IT Consultant and "geek"! As a contributing author on GBD, he covers all things tech and writes reviews for a variety of products and services.

Related Articles

2 Comments

  1. Eli Etherton July 9, 2014 at 2:29 pm

    Something I would have never thought of…

  2. Nathan Smutz July 10, 2014 at 1:11 am

    If the exercise they used to test these languages is typical of ecconomist work, and the worst case ran in seconds, then maybe they’re testing the wrong thing.

    In a lot of fields, they’re recognizing that programmer time and easier avoidance of programmer error are the best things to optimize.

    Running time is easy to test; but may really be a minor issue.

Leave a comment

Back to Top