2010/1/13 HommeDeJava <[email protected]>

> Greetings folks,
>
> I came across this pretty strange testbed which compares Java and C++
> performance on <a href="http://www.developer.com/java/article.php/
> 3856906/Java-vs-C-The-Performance-Showdown.htm<http://www.developer.com/java/article.php/%0A3856906/Java-vs-C-The-Performance-Showdown.htm>">
> Gamelan.com</a> and
> promoted by a Java/Open Source Daily newsletter, from Gamelan which I
> supposed should promotes Java and Open Source despite a lot of
> Microsoft ads ;-)
>
> The testbed claims to show that C++ is 25,000 times faster than Java.
> From what I know about the JVM, I was expecting C++ to be at most 5 to
> 10 times faster.
> Am I wrong?
>
> Maybe the C++ compiler/optimizer had removed dead code from the
> testbed.
> Furthermore, in order to perform as fast as stated, the computer
> should run over 20 Ghz ???
>
> Furthermore, some readers have carefully observed, in order to ensure
> such a performance, the computer should run at over 20 GHz.
>
> What do you think about this so-called testbed?
>

there's a fatal flaw in the test - the compute method doesn't return
the result of the computation, alter any of the arguments, or have
any side-effects - which means to the rest of.the program it can
be safely considered as a no-op

the C compiler (with optimization) realizes this and removes the
method call, which explains the crazy fast times as it's not really
doing anything except the timing calls

the HotSpot client JVM (and JIT) doesn't detect this which is why
it appears much slower, because it's actually doing the calculation

however if you turn on escape analysis (is this still in the 6.0 builds?)
or use the IBM 6.0 JVM which comes with escape analysis enabled
then you get results that are more in line with C:

   Java computing took 4  (ms)

and if you run the compute method enough times beforehand so the
JIT optimizes it (a few thousand times should do it) then you get even
better results:

   Java computing took 0  (ms)

HTH :)

Are there any good benchmarks comparing C and Java?
>
> Thanks
>

-- 
Cheers, Stuart
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.

Reply via email to