Giter Site home page Giter Site logo

jesusfv / comparison-programming-languages-economics Goto Github PK

View Code? Open in Web Editor NEW
260.0 260.0 131.0 78 KB

A Comparison of Programming Languages in Economics

License: MIT License

C++ 16.31% C 14.70% C# 5.23% Fortran 4.80% JavaScript 5.40% HTML 0.12% Java 6.54% Julia 3.05% Mathematica 10.22% MATLAB 6.04% Python 11.23% R 8.16% Swift 4.92% Nim 3.28%

comparison-programming-languages-economics's People

Contributors

anastasios-stamoulis avatar infogulch avatar jesusfv avatar leitec avatar marcolugo avatar perogycook avatar sangonz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

comparison-programming-languages-economics's Issues

A Haskell implementation

I look forward to the companion paper on functional programming languages.

A implementation in Haskell by me, with suggestions from people on the internet, is here
https://github.com/jmoy/avb-econ-hs

Right now it runs in about twice the time as RBC_CPP.cpp on my machine

time measurements

A little bit late now, but I thought I'll mention it anyway.

I all of the code, you print some progress every 10 iterations. These are executed in the part of the execution that is measured for time. That's not a very good idea. Printing something to the console is very unpredictable. It will or will not block your execution depending on the state of the machine your running the benchmarks on. At least, it will allow for process switches, invalidating your measurements.

Just for the fun of it, I did remove that part and moved the remaining printing outside of the measured part. E.g. for the C++ example that had a 5% effect on the timings. For Julia, it has a 25% effect on the timings.

Since I was busy anyway, I did add '--check-bounds=no' to the Julia command since you also do '-O3' for C++. I also changed 'maximum(abs(...))' to 'max(abs(...))' in the Julia code, since it is available in the base Julia.

These minor changes did reduce the time of both the C++ and the Julia code. But, more importantly, it makes the Julia code run faster then the C++ code. And I guess that changes some of the conclusions in the paper ?

Greetings,
Wilffried
[email protected]

Timing in C/C++/Fortran

Hi Jesus, you cannot use clock() portably to measure any kind of time in C/C++ codes. This is because on Windows, clock() refers to wall-clock time (http://msdn.microsoft.com/en-us/library/4e2ess30.aspx), and elsewhere (POSIX etc) it refers to CPU time (http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.15.html). Which are you trying to measure? If you are trying to measure wall-clock time, use QueryPerformanceCounter on Windows and clock_gettime with a monotonic clock on POSIX.

For Fortran, ETIME() is not part of any Fortran standard and should not be used. Its behavior is implementation defined. The way you are using it, you are measuring user CPU time, however (from the Intel site): "On single processor systems, returns the elapsed CPU time, in seconds, of the process that calls it. On multi-core or multi-processor systems, returns the elapsed wall-clock time, in seconds." If you are measuring CPU time, use CPU_TIME, otherwise, for wall-clock time, use SYSTEM_CLOCK. These are part of the Fortran standards.

If you tell me what you're trying to measure (wall-clock time or CPU time), I can submit pull requests.

By the way, I noticed you have a copy of your Fortran code for the Intel compiler with the call to ETIME simply commented out. You need to add "USE IFPORT" at the top to use ETIME with the Intel compiler.

Allocating arrays in C++ code

Hi again,

Just as a last note, the way you are allocating your large arrays is actually a feature of C99 (variable-length arrays). If you wanted to do this in a true C++ fashion, you could either use new/delete, vectors, or as of C++11, arrays. Section 3 of the C++ code could be replaced with:
array<array<double, nGridProductivity>, nGridCapital> mOutput, mValueFunction, mValueFunctionNew, mPolicyFunction, expectedValueFunction;
if you #include <array> and compile with -std=c++11.

transpose in Fortran example

With optimization on most Fortran compilers will remove the issue, but you seem to declare a constant array and then transpose it,
and then transpose it again (returning it to the values before the first transpose) on each pass. If I am reading that correctly you can eliminate the transpose calls in the Fortran example. With optimization turn offed it might make a significant difference. With optimization on it is very likely the operations were removed from the loop and the change would be negligible.

Transposing constant matrices in loops in Fortran and MATLAB codes

Hi, you are defining a 5x5 array called 'mTransition' in all of these codes. The array never changes. In the Fortran and MATLAB versions, you are transposing it inside of loops which creates array temporaries and is an unfair handicap as you are not transposing the array in the other (C++ for example) codes. You should transpose mTransition just once for these codes instead of re-transposing inside of loops. In Fortran's case, it looks like you can just get rid of all calls to transpose for mTransition as you already transpose it once right after definition.

What about Ada?

What about Ada?

I suspect it is a little faster than C++, mainly thanks to explicit parameter modes (what may allow to use registers for in-out parameters) instead of how C++ pass pointers for the same deal (and the compiler cannot be sure that the pointer is not null and that registers can be used instead).

However Ada has the drawback of storing two integers with each array (to maintain its range). In principle, this can be get rid of with an optimizing compiler which would not store the lowest index of an array, provided that this index can be restored from a record discriminant. This can be used for creating optimizing collections, which are faster than plain arrays. (I don't know whether this my optimization idea for Ada is already implemented.)

License?

I do not recall seeing a license for the code given in the paper, nor do I see one here. This generally means people are hesitant to use the results for anything other than personal use.

Rcpp comments

I'm not directly involved, but I notice that there's some discussion among Rcpp aficionados here, suggesting that the sourceCpp call here should be moved outside the loop for a fair comparison ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.