Updated Java vs. C++

Updated to bring to the current state of the art in 2003 results of Java vs. C++
updates:
2/16/2003: added results sent by Dave Marquar
2/16/2003: initial version

Comparison using generic bubble sort

Please read first original article Java vs. C++.

Source code

I have copied from the original website and made available here the source code with following modifications:

I have also added two handy script ot simplify compiling code with VC++ (vc_compile.bat) and with JAVA (java_compile.bat).

C++ version

Code: sort_pointer.cpp sort_object.cpp sort_vector.cpp sort_STL.cpp

Java version

Code: Sort.java SortVector.java SortArrayList.java

Updated Results

I have run tests on 850 MHz Pentium III PC running Windows 2000 SP3: (to compile C++ code i used command line cl /O2 and for vector and STL added /GX option) detailed log of test execution is available.

Version Execution Environment Execution Time
C++ pointer MS Visual C++ 6.0 SP5 19s
C++ object MS Visual C++ 6.0 SP5 11s
C++ vector MS Visual C++ 6.0 SP5 13s
C++ STL MS Visual C++ 6.0 SP5 12s
Java array HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 103s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 89s
Java Vector HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 355s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 241s
Java ArrayList HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 328s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 114s

I have also received from Dave Marquar interesting results (see that client Hotspot Vector is faster than ArrayList) for running Java tests on an Athlon 2.0+ running Windows XP with JDK 1.4.1:

Version Execution Environment Execution Time
Java array HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 50s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 46s
Java Vector HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 144s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 105s
Java ArrayList HotSpot Client VM (build 1.4.1_01-b01, mixed mode) 149s
HotSpot(TM) Server VM (build 1.4.1_01-b01, mixed mode) 42s

There are few interesting observations that one an make. First: using arrays instead of Vector/ArrayList in very computational intensive applications may make sense. Secondly the difference between Vector and ArrayList is no longer significant in moden JVMs. Finally Java Hotspot server is very good optimizer and using ArrayList in such setup gives performance close to native java array and this is indeed impressive result!

Aleksander Slominski


Last modified $Id: index.html,v 1.3 2003/02/17 04:15:05 aslom Exp $