Home » Code » A comparison of programming languages in economics

A comparison of programming languages in economics

Tyler Cowen, Marginal Revolution, A comparison of programming languages in economics, here. Adorable, see also here.

Our first result is that C++ and Fortran still maintain a considerable speed advantage with respect to all other alternatives. For example, these compiled languages are between 2.10 and 2.69 times faster than Java, around 10 times faster than Matlab, and around 48 times faster than the Pypy implementation of Python. 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++11 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 2008 is simple and compact ñand, thus, relatively easy to learn ñ and it can take advantage of large amounts of legacy code.14 Third, even for our very simple code, there are noticeable di§erences among compilers. We Önd speed improvements of more than 100 percent between di§erent executables of the same underlying code (and using equivalent optimization compilation áags). 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, they do less well in a Windows machine. The deterioration in performance of the Clang compiler was expected given that the goal of the LLVM behind it is to minimize compilation time and executable Öle sizes, both important goals when developing general-use applications but often (but not always!) less relevant for numerical computation. Our fourth result is that Java imposes a speed penalty of 110 to 169 percent. Given the similarity between Java and C++ syntax, there does not seem to be an obvious advantage for choosing Java unless portability across platforms or the wide availability of Java programmers is an important factor.

They went and flipped the -O3 switch:

Our Mac machine had an Intel Core i7 @2.3 GHz processor, with 4 physical cores, and 16 GB of RAM. It rsn OSX 10.9.2. Our Windows machine had an Intel Core i7-3770 CPU @3.40GHz processor, with 4 physical cores, hyperthreading, and 12 GB of RAM. It ran Windows 7, Ultimate-SP1. The compilation áags were: 1. GCC compiler (Mac): g++ -o testc -O3 RBC_CPP.cpp 2. GCC compiler (Windows): g++ -Wl,–stack,4000000, -o testc -O3 RBC_CPP.cpp 3. Clang compiler: clang++ -o testclang -O3 RBC_CPP.cpp 4. Intel compiler: icpc -o testc -O3 RBC_CPP.cpp 5. Visual C: cl /F 4000000 /o testvcpp /O2 RBC_CPP.cpp 6. GCC compiler: gfortran -o testf -O3 RBC_F90.f90 7. Intel compiler: ifortran -o testf -O3 RBC_F90.f90 8. javac RBC_Java.java and run as java RBC_Java -XX:+AggressiveOpts.


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: