Perl, Python, Ruby, PHP, C, C++, Lua, tcl, JavaScript and Java comparison
raid6.com.au
raid6.com.au
#include <time.h>
The program is using its own standard library to time itself, and I presume this applies to the other specimen languages. In order for this to be a fair test, the timing method utilised should be the same for all languages in question.I can testify from my own experience that time() in time.h is highly unreliable, my uttering of "naut mississippi", "one mississippi", "two mississippi" was far more precise.
Of course the above does not apply to memory usage.
Still I'd love to see the same benchmarks done with more idiomatic code.
Will somebody explain to me what's going on? Maybe I'm missing something.
Sometimes Perl does things more uniformly across different systems than would be done on a single system with a different language like C. For example, this is Perl's malloc implementation: http://perl5.git.perl.org/perl.git/blob/7742aa6637b99424497e...
Depending on what you are doing, Perl may have a more efficient way of tackling the problem. This isn't to say you couldn't do it in that exact same way in a different language and find a faster result; it's just that Perl already does things efficiently, so you don't have to spend time tuning algorithms.
So I suspect that the C code wasn't written as optimally as it could be.
Maybe the point is that a naive implementation in Perl has better performance than a naive implementation in other languages?
For the C version, just changing strcat(gstr, str); to strcat(&gstr[lngth - str_len], str); cuts the execution time by 1/4 for the longest cases.
original: 471sec 4096kb
changed: 356sec 4096kb
gcj is dead.