Suitability (of Java)

Don Smith dss-lfs at cfl.rr.com
Sat Apr 3 07:53:46 PST 2004


Tushar Teredesai wrote:
> Don Smith wrote:
> 
>> Tushar Teredesai wrote:
>>
>>>
>>> Do you have any references to any recent benchmarks on the speed 
>>> comparison?
>>>
>>> Especially with JIT, the performance of C++ and Java code is 
>>> comparable, especially when the new programs are loaded in an already 
>>> existing JVM. And the productivity is higher (less bugs).
>>>
>>
>> Try these. Using JDK 1.3.1 (admittedly old) on my 200Mhz x86 system 
>> (with a loop of only 100,000,000 instead of 1G) I get 16 seconds for 
>> the C++ code and 36 seconds for Java (after the JVM is loaded).
>>
>> Can someone try this with the latest JDK to see if this still holds?
>> JIT would probably solve this problem. (I have to use the older JDK 
>> because that's what my main customer is using.)
> 
> 
> $ c++ -v
> Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
> Configured with: ../gcc-3.3.3/configure --prefix=/usr 
> --enable-languages=c,c++,f77,java,objc --enable-threads=posix 
> --enable-__cxa_atexit --enable-clocale=gnu --with-system-zlib 
> --enable-shared --without-x
> Thread model: posix
> gcc version 3.3.3
> 
> $ java -version
> java version "1.4.2-internal"
> Java(TM) 2 Runtime Environment, Standard Edition (build 
> 1.4.2-internal-tt-1080196214)
> Java HotSpot(TM) Client VM (build 1.4.2-internal-tt-1080196214, mixed mode)
> 
> $ c++ -o Increment Increment.cpp
> 
> $ javac Increment.java
> 
> $ time ./Increment
> Evens: 500000000 Odds: 500000000
> Time: 17.191453
> 
> real    0m17.231s
> user    0m17.140s
> sys     0m0.000s
> 
> $ time java Increment
> Evens: 500000000 Odds: 500000000
> Time: 10.959
> 
> real    0m11.258s
> user    0m11.130s
> sys     0m0.010s

That's pretty cool. Thanks. And the JIT seems optimize the code as well.

How efficient is the compiler? That's a pretty small program and it 
looks like it took about .2 seconds to compile.

Did you try the Allocate one also? On my system the Java version took 40 
times longer. Of course that's a slightly unfair test since it picks on 
the garbage collector. And if you have 4GB of physical memory you might 
not see a difference unless you adjust the iteration counter upwards.

Now if they would just add delete to Java...




More information about the hlfs-dev mailing list