An economics researcher at UPenn recently published the following paper:
http://economics.sas.upenn.edu/~jesu..._languages.pdf
Here are the codes:
https://github.com/jesusfv/Compariso...ages-Economics
Looking at the code makes my eyes bleed.
An economics researcher at UPenn recently published the following paper:
http://economics.sas.upenn.edu/~jesu..._languages.pdf
Here are the codes:
https://github.com/jesusfv/Compariso...ages-Economics
Looking at the code makes my eyes bleed.
O_o
I can't speak for the Fortran; as for the C++, the code is really just C with some C++ tools used.
I would not say "eye bleedy", but very much not idiomatic.
*shrug*
At least the style used, though an uncommon mix, is very consistent.
Because I haven't Fortran-ed in a long age*, you'd have to provide some sort of overview.
Soma
* I also never really learned canonical Fortran.
“Salem Was Wrong!” -- Pedant Necromancer
“Four isn't random!” -- Gibbering Mouther
For Fortran:
1) Mixing double/single precision math (5.0 is taken as single-precision in Fortran as opposed to double in C/C++)
2) ETIME() is a compiler extension and implementation-defined
3) real(8) is not portable or guaranteed to be double precision, must use SELECTED_REAL_KIND
4) using list-directed I/O makes Fortran print out all significant figures of floating-point numbers, causing extra I/O
5) transposing an array that never changes every iteration of the main loop
I thought the C++ was a dirty hack; you have to specify -Wl,-stack=4000000 on Windows to get it to compile because of the variable-length arrays. Really, both the Fortran and C++ codes ought to be written to dynamically allocate this memory, as it's up to the compiler as to whether or not automatic arrays are on the heap or stack.
O_oI thought the C++ was a dirty hack; you have to specify -Wl,-stack=4000000 on Windows to get it to compile because of the variable-length arrays.
I see what you are saying. You kind of went the other way. You started with "The code says C++ on the label so should be C++ code.". I started with "The code is really just C code regardless the label.". (In other words, I think the C++ should be removed leaving just C99.) If you go that way, the C++ is definitely worse that I suggested.
Soma
“Salem Was Wrong!” -- Pedant Necromancer
“Four isn't random!” -- Gibbering Mouther
Either way would work for me, change it all to C or change it all to C++. If C, I'd replace the VLAs with mallocs for aforementioned reasons. gcc is too dumb to recognize that those arrays need to be stored on the heap.
Guess I'm just picky. In all honesty, I decided to crap all over this because of the published results which are clearly wrong. I believe anyone who tries to say that GCC is faster than Intel or Clang to be entirely wrong. From my experience, (for Fortran vs. C/C++), Fortran is around 5-10% faster for equivalent code, and for compilers, Intel is the fastest, followed by Clang then GCC. Not sure where MSVC comes in terms of speed.
Clang is really faster than GCC? GNU, how could you betray me?
For most of my code, Clang is around 10% faster than gcc. Clang has great potential as I find it to be the best in terms of warning generation and it can be as fast as the Intel compiler at times.
Wait, just to be specific, are we talking about compilation time or the time it takes to run the executable? All I care about is execution time, tbh. And I assumed that was what we were talking about.
And to actually add to this topic, I saw some academic meshing code that was terribly written. No CamelCase or underscores and all C code written under a C++ compiler, just using a constructor maybe once or twice.
Execution time*, though Clang is definitely faster than gcc at compilation time as well, by about 15%. I don't really care about compilation time either unless I'm compiling a huge project.
*I test everything with -O2 because this is the recommended optimization level for most compilers (references: intel compiler docs, gentoo wiki, various other places I've read, google it)
Picking on researchers... not fair! Their code may suck but that's not what they care about.
At a research heavy company like mine there is a clear division between research and production code. It's better to free the researchers from the burden of writing solid code so they can focus on producing intellectual output.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
As I said before, I only picked on him because he said Fortran was slower than C/C++, which is wrong.
Edit: for numerical computation
Last edited by Epy; 06-18-2014 at 04:47 PM.
You may have glossed over a particularly important bit here
IMO this makes the whole comparison pretty silly. They use (as closely as possible) the exact same implementation in each language. They make little to no effort to use a somewhat optimal or idiomatic implementation in any particular language, or leverage any language features that could seriously shift the results. They basically hold everybody to the lowest common denominator. On one hand, it's "fair", on the other it provides little useful information. It's like comparing a jeep, street bike and minivan by simply looking at the 0-60mph speeds. Sure, the street bike can do it fastest, but it can't transport a family of 5 nor can it handle dirt roads or stream crossings very well.Originally Posted by A Comparison of Programming Languages in Economics p4
I do not know Fortran but the Java code looks pretty decent compared to code that I have seen in "enterprise" applications. So heavily patched for break-fixes, customized, gone through hundreds of "coders" who do not know what the original author intended to do. The end version(v1001.11) is delicious spaghetti code ready to kill your sleep and weekend plans. Either I am missing something or you and I have very different definitions for the word "terrible".
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer