This project contains the source code referenced in the paper A Comparison of Programming Languages in Economics by S. Borağan Aruoba and Jesús Fernández-Villaverde.
The main fork will remain basically unchanged to allow researchers to check our basic results.
We solve the stochastic neoclassical growth model, the workhorse of modern macroeconomics, using
C++11
,Fortran 2008
,Java
,Julia
,Python
,Matlab
,Mathematica
, andR
. 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 aMac
and in aWindows
computer and comment on the strength and weakness of each language.
RBC_CPP.cpp
: C++ code.RBC_CPP_2.cpp
: C++ code, more idiomatic but slightly slower.RBC_F90.f90
: Fortran code.RBC_Java.java
: Java code.RBC_Julia.jl
: Julia code, to run RBC_Julia; @time main().RBC_Matlab.m
: Matlab code.RBC_Matlab_Inside_Loop.m
: Matlab code with Mex file.inside_loop_mex.cpp
: Mex file for 5.RBC_Python.py
: Python code for CPython and Pypy.RBC_Python_Numba.py
: Python code for Numba.RBC_R.R
: R code.RBC_R_Compiler.R
: R code compiled.RBC_Mathematica
: Mathematica code.RBC_Mathematica_Imperative
: Mathematica code with imperative structure.RBC_Mathematica_PartialCompilation
: Mathematica code with imperative structure and partial compilation.RBC_Mathematica_Plain_Text.tx
: Mathematica code in plain text for those without Mathematica.RBC_Mathematica_Imperative_Plain_Text.text
: Mathematica code in plain text, imperative version.
- GCC compiler (Mac):
g++ -o testc -O3 RBC_CPP.cpp
- GCC compiler (Windows):
g++ -Wl,--stack,4000000, -o testc -O3 RBC_CPP.cpp
- GCC compiler (Mac):
g++ -o testc -O3 -std=gnu++11 RBC_CPP_2.cpp
- Clang compiler:
clang++ -o testclang -O3 RBC_CPP.cpp
- Intel compiler:
icpc -o testc -O3 RBC_CPP.cpp
- Visual C:
cl /F 4000000 /o testvcpp /O2 RBC_CPP.cpp
- GCC compiler:
gfortran -o testf -O3 RBC_F90.f90
- Intel compiler:
ifortran -o testf -O3 RBC_F90.f90
javac RBC_Java.java
and run asjava RBC_Java -XX:+AggressiveOpts
In all cases with a JIT, you may want to warm up the JIT before testing for speed.