Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Java versus C Speed Comparison

Author: Matt Taylor

Date: 09:37:18 01/07/03

Go up one level in this thread


On January 07, 2003 at 05:17:20, Graham Laight wrote:

>On January 06, 2003 at 19:33:18, Matt Taylor wrote:
>
>>On January 06, 2003 at 13:33:24, Russell Reagan wrote:
>>
>>>On January 06, 2003 at 12:36:19, Graham Laight wrote:
>>>
>>>>Java is a compiled language - it ought to be nearly as quick as C.
>>>
>>>It's only compiled to byte code, not machine code, so there is still some
>>>interpreted-like behavior going on. I have heard that Java is about 2x as slow
>>>as its C/C++ equivalent. One additional thing that I think will slow Stuart down
>>>is that he is using bitboards in Java. I have never tried myself, but I have
>>>always heard that bitboards in Java are slow (when compared to bitboards in
>>>C/C++).
>>
>>Rumor has it that platform-specific Java compilers exist. I've never seen one. I
>>can't vouch for the 64-bit performance of Java, though I would have expected it
>
>This is surely dependant on the compiler which is available for your particular
>computer. I would think that by default, Java would be optimised for a 32 bit
>processor.

Likewise are C/C++ compilers that target 32-bit machines, are they not? The
difference here is that Java had 64-bit types from its release. Therefore the
compilers are more likely to pay attention to use of 64-bit types and produce
better 64-bit code.

>>to be more mature in that respect than C/C++. Also, the JIT compiled JVMs are
>>quite fast. You pay the JIT penalty once each time you start the program, but
>>afterward it'll be running native code.
>
>What you seem to be saying here is that you can have a Java compiler installed
>into your web browser that will compile the Java code into machine code for the
>computer you're running. If so, I assume this has to be installed separately -
>and that the default is that that the Java applet comes as "tokenised" byte code
>which your web browser interprets.

Yes, this is called a "Just In Time" (JIT) compiler. It takes the bytecodes and
compiles them to machine code on the fly. The JIT is allowed to make decisions
about which code gets compiled and which code gets interpreted.

Whenever the web browser encounters a Java program, it invokes your JVM to
execute it. The JIT compilers are basically JVMs that compile to machine code
and execute. Most commericial x86 emulators follow the same strategy,
particularly when they're executed on x86. (Recompiling x86->x86 is pretty fast,
no?)

>>There was some benchmark a long time ago on cnet or the like, can't remember
>>where I saw it...anyway, it showed JIT performance exceeding C/C++ performance
>>in some cases. That does raise eyebrows. Makes you wonder how poorly-written the
>>C/C++ code was. Either way, it means that JIT code can be relatively fast.
>
>To achieve this, either the program must have been compiled to machine code, or
>the test must have carefully selected operations at which a web browser happens
>to be exceptionally good.
>
>-g
>
>>-Matt

Yes...it is unfortunate that they never released the source. I am always
suspicious when benchmarks are not released with source -- how do I know that
it's a fair benchmark?

-Matt



This page took 0.02 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.