Update 2009 JAVA 1.6 reaches ~95% performance of C++

Is JAVA fast? Yes, since introduction of SSE and SSE2 streaming commands and other major enhancements, JAVA 1.5 is closing the gap. The best proof is JAKE2 a resource and CPU hungry 3D game engine. Some years ago such an approach would have been laughable.

However the SciMark benchmarks show, that up to 70% of the C++ speed can be reached by JAVA. But there are major differences between operating systems and versions. For the fastest implementation, you should download the free server version of SUNs JAVA engine. This will speed up your code up to 40%. Hence every command must include "java -server" as run command.

Is it a good benchmark? Yes because it contains results from diverse platforms and different CPUs and the code did not change since then. Is it a bad benchmark? Yes, because it only checks for floating point computational speed (good for science, games, applications) and it is only single-threaded (a big NO NO, as it can run only one one CPU core).

Compiler optimization and benchmarks

The free MS Visual C++ Express compiler was compared against the JAVA compiler v1.5 (JAVAC optimization with -O) For comparison a 25% higher clocked Intel CPU result was included, with Intel LINUX C++ compiler.


SCIMARK AMD compiler options
SciMark2 Numeric Benchmark, see http://math.nist.gov/scimark
Opteron 2.8 GHz (single threaded programs) WIN XP2

WIN XP2
MS Visual C++
Opteron 2.8 GHz
WIN XP2
JAVA 1.5 server
Opteron 2.8 GHz
LINUX
Intel C++
Xeon 3.6 GHz
fast precise SSE fast SSE precise SSE2 fast SSE2 precise MAX
Small Problem
Composite Score: 802.03 811.34 815.43 819.47 708.29 728.52 819.47 584 943
FFT Mflops: 734.42 729.5 744.13 734.42 660.7 676.32 744.13 457 521
SOR Mflops: 868.39 927.31 868.39 920.23 822.43 893.76 927.31 906 1092
MonteCarlo Mflops: 163.63 164.38 184.75 184.75 166.78 165.96 184.75 80 447
Sparse matmult Mflops: 762.49 773.29 773.29 776.72 748.98 748.98 776.72 439 832
LU Mflops: 1481.24 1462.2 1506.57 1481.24 1142.54 1157.55 1506.57 1040 1827

The results together with the JAVA, Assembler and C++ EXE files can be downloaded here. A comprehensive list of different JVM and compiler speeds for several problems can be found at shudo.net. A bunch of other sites comparing JAVA versus C on different platforms and with different JVMs can be found google. The comprehensive JAVAGRANDE benchmarks can be found at EPCC. Another point of interest may be the C# (C-Sharp) version of SciMark, which is slower than JAVA giving a score of 476 on this machine.

Update 2009 with the new JAVA 1.6 (64-bit) compiler

The comparison is not complete and not fair. For JAVA 1.6 the SUN amd64 compiler was used, for C the MS Visual C++ compiler with SSE2 but in 32 bit mode was used. The machine was a Core i7 3GHz @ 3.4GHz and 12 GByte DDR3 RAM running VISTA 64 bit. No other optimizing compiler (Intel, PathScale) was included.

The JAVA Benchmark results:

java.exe -server -Xms1600m -Xmx1600m -XX:+AggressiveHeap -cp ..\.. jnt.scimark2.commandline
SciMark 2.0a

Composite Score: 1265.1385420292804
FFT (1024): 795.7301642787169
SOR (100x100): 1449.3832764603712
Monte Carlo : 504.104115638433
Sparse matmult (N=1000, nz=5000): 1077.0090318677676
LU (100x100): 2499.4661219011127


java.vendor: Sun Microsystems Inc.

java.version: 1.6.0_17

os.arch: amd64

os.name: Windows Vista

os.version: 6.0


The C++ Benchmark results (Microsoft C++)

C:\bench\scimark\Scimark2-AMD\Release\asm>.\SSE2precise\Scimark2-AMD.exe
** **
** SciMark2 Numeric Benchmark, see http://math.nist.gov/scimark **
** for details. (Results can be submitted to This email address is being protected from spambots. You need JavaScript enabled to view it.) **
** **
Using 2.00 seconds min time per kenel.
Composite Score: 1318.78
FFT Mflops: 1202.92 (N=1024)
SOR Mflops: 1460.37 (100 x 100)
MonteCarlo: Mflops: 232.21
Sparse matmult Mflops: 1082.79 (N=1000, nz=5000)
LU Mflops: 2615.58 (M=100, N=100)


The GNU C++ compiler (SSE3 tested but slower)

Cygwin gnu c compiler
CFLAGS = -g -m32 -O3 -ffast-math -msse2 -mfpmath=sse
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

$ ./scimark2.exe
** **
** SciMark2 Numeric Benchmark, see http://math.nist.gov/scimark **
** for details. (Results can be submitted to This email address is being protected from spambots. You need JavaScript enabled to view it.) **
** **
Using 2.00 seconds min time per kenel.
Composite Score: 1069.87
FFT Mflops: 882.49 (N=1024)
SOR Mflops: 1101.12 (100 x 100)
MonteCarlo: Mflops: 297.52
Sparse matmult Mflops: 1126.05 (N=1000, nz=5000)
LU Mflops: 1942.15 (M=100, N=100)


Download archive with JAVA, C++, ASM, EXCEL code here [ZIP]. For a more complete coverage of language benchmarks go to the Computer Language Benchmarks Game which covers 30 different modern languages.

The overall speed can be greatly improved by compiling specialized libraries for mathematical functions into the package.