Razii said:
> On Tue, 06 May 2008 05:49:03 +0000, Richard Heathfield
> <rjh@[EMAIL PROTECTED]
> wrote:
>
> This was at least a nice change. Instead of abusive ad hominem posts
> from the trolls, you posted at least something on topic. You should be
> commended for not trolling.
>
>>Why? The fault, dear Razik, lies not in our languages, but in our
>>authors. On my system, neither the C++ version nor the Java version
would
>>compile.
>
> Perhaps then you should contribute the better C++ version to shootout
> site?
<shrug> Can't be doing with all that, given that optimal solutions are
forbidden (not allowed to do character-based I/O, which is a stupid
restriction designed to favour limp-along languages). If someone else
wants to put this version up (which is also legal C, by the way), feel
free:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf[129] = {0};
long int sum = 0;
while(fgets(buf, sizeof buf, stdin) != NULL)
{
sum += strtol(buf, NULL, 10);
}
printf("%ld\n", sum);
return 0;
}
> I can only judge by what is available.
Nah, you can always write your own.
> And what kind of compilers are you using?
If that question is im****tant, it's the wrong kind of question for
comp.lang.c. :-)
> C++ I can understand, but why won't Java
> version compile on your system?
Because I didn't do it right, it seems. Fixed that, and that means I can
compare results on my system. I now get 0.058 seconds for the 6KB supplied
test file, compared to 0.003 seconds for the C version.
So by my reckoning, C is almost 20 times faster than Java on my system.
I recompiled my C version as C++, too. Here are the final results:
C: 0.003
C++: 0.021
Java: 0.058
I conclude on the basis of this fully representative and statistically
significant sample that C rocks, Java sucks, and C++ isn't sure which it
is.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www.
+rjh@[EMAIL PROTECTED]
users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


|