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_C.c
: C code.RBC_CPP.cpp
: C++ codeRBC_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 runinclude("RBC_Julia.jl"); @time main()
.RBC_Matlab.m
: Matlab code.RBC_Matlab_Inside_Loop.m
: Matlab code with Mex file.inside_loop_mex.cpp
: Mex file for 8.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_Rcpp.R
: R code with Rcpp.InsideLoop.cpp
: C++ function for Rcpp.RBC_Mathematica
: Mathematica code.RBC_Mathematica_Imperative
: Mathematica code with imperative structure.RBC_Mathematica_PartialCompilation
: Mathematica code with imperative structure and partial compilation.RBC_CS.cs
: C# code.RBC_JS.js
: Javascrip code.RBC_Python_Cython.py
: Cython code.RBC_Swift.swift
: Swift code.
- 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
RBC_C.c
can be compiled in C, C++ and Objective-C:clang -o testc -x <language> -O3 RBC_C.c
with<language>
=c
,c++
orobjective-c
. Same for GCC.- Swift:
swiftc -o testswift -O RBC_Swift.swift -sdk $(xcrun --show-sdk-path --sdk macosx)
In all cases with a JIT, you may want to warm up the JIT before testing for speed.