vs

 1 : Are the Java programs faster? At a glance.

Each chart bar shows, for one unidentified benchmark, how much the fastest Java program used compared to the fastest C# Mono program.

(Memory use is only compared for tasks that require memory to be allocated.)


These are not the only compilers and interpreters. These are not the only programs that could be written. These are not the only tasks that could be solved. These are just 10 tiny examples.

 2 : Are the Java programs faster? Approximately.

Each table row shows, for one named benchmark, how much the fastest Java program used compared to the fastest C# Mono program.

(Memory use is only compared for tasks that require memory to be allocated.)

 Java used what fraction? used how many times more? 
Benchmark Time Memory Code
 k-nucleotide1/3±
 regex-dna1/3
 spectral-norm1/2 
 reverse-complement1/2±
 fasta± 
 binary-trees±±
 fasta-redux± ±
 mandelbrot± ±
 pidigits± ±
 fannkuch-redux± 
 n-body± ±
 Java used what fraction? used how many times more? 
Time-used  |-  |---  25% median  75%  ---|  -|
(Elapsed secs)1/31/31/2±±±±

± read the measurements and then read the program source code.

 3 : Are the Java programs faster? Measurements.

These are not the only tasks that could be solved. These are just 10 tiny examples. These are not the only compilers and interpreters. These are not the only programs that could be written.

For each named benchmark, measurements of the fastest Java program are shown for comparison against measurements of the fastest C# Mono program.

Program Source Code CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
 k-nucleotide 
Java31.1831.211,189,8121844  1% 1% 0% 100%
C# Mono103.48103.54319,1121404  1% 1% 1% 100%
 regex-dna 
Java22.1222.13564,9521377  2% 1% 1% 100%
C# Mono73.1973.22375,576594  0% 1% 1% 100%
 spectral-norm 
Java16.3116.3120,440950  1% 1% 0% 100%
C# Mono29.4729.4819,476459  0% 1% 0% 100%
 reverse-complement 
Java1.691.69519,612745  0% 1% 0% 100%
C# Mono2.962.97175,5201099  1% 0% 1% 100%
 fasta 
Java4.934.9327,6682457  0% 1% 0% 100%
C# Mono7.157.1619,4121180  1% 0% 1% 100%
 binary-trees 
Java16.4116.44521,176584  0% 1% 1% 100%
C# Mono20.1020.13114,172654  0% 1% 1% 100%
 fasta-redux 
Java1.931.9321,6681443  3% 1% 1% 100%
C# Mono2.302.3019,3201438  1% 0% 1% 100%
 mandelbrot 
Java26.9626.9859,240796  1% 0% 0% 100%
C# Mono30.5530.5651,544986  1% 0% 1% 100%
 pidigits 
Java4.144.1421,844938  1% 0% 1% 100%
C# Mono3.983.9819,6361026  1% 1% 1% 100%
 fannkuch-redux 
Java67.4867.5021,4481282  1% 1% 0% 100%
C# Mono64.4864.5018,616564  0% 1% 0% 100%
 n-body 
Java24.5024.5219,6361424  1% 0% 1% 100%
C# Mono22.0422.0419,4121305  0% 1% 1% 100%

 4 : Are there other Java programs for these benchmarks?

Remember - those are just the fastest Java and C# Mono programs measured on this OS/machine. Check if there are other implementations of these benchmark programs for Java.

Maybe one of those other Java programs is fastest on a different OS/machine.

 5 : Are there other faster programs for these benchmarks?

Remember - those are just the fastest Java and C# Mono programs measured on this OS/machine. Check if there are faster implementations of these benchmark programs for other programming languages.

Maybe one of those other programs is fastest on a different OS/machine.

 Java : ubiquitous jit server virtual machine 

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)

Home Page: Java SE at a Glance

Download: Java SE Downloads

Let's see how much, or how little, the time taken to invoke the JVM might contribute to the usual Java program times shown in the benchmarks game. Here are some additional (Intel® Q6600® quad-core) elapsed time measurements, taken after the Java programs started and before they exited.

In the first case (Cold), we simply started and measured the program 66 times; and then discarded the first measurement leaving 65 data points.

   public static void main(String[] args){
      for (int i=0; i<1; ++i){ 
         System.gc(); 
         long t1 = System.nanoTime();
         nbody.program_main(args);
         long t2 = System.nanoTime();
         System.err.println( String.format( "%.6f", (t2 - t1) * 1e-9 ) );         
      }
   }

In the second case (Warmed), we started the program once and repeated measurements again and again and again 66 times without restarting the JVM; and then discarded the first measurement leaving 65 data points.

   public static void main(String[] args){
      for (int i=0; i<66; ++i){ 
         System.gc(); 
         long t1 = System.nanoTime();
         nbody.program_main(args);
         long t2 = System.nanoTime();
         System.err.println( String.format( "%.6f", (t2 - t1) * 1e-9 ) );         
      }
   }

Compare these additional measurements against the usual Java program measurements shown in the benchmarks game --

"1.7.0_06" Java HotSpot(TM) 64-Bit Server VM
System.nanoTime()  1) Cold   2) Warmed   
  mean σ mean σ   usual
meteor contest   0.0118s 0.0007 0.0016s 0.0002 0.22s
fasta-redux   2.45s 0.00 2.32s 0.00 2.51s
spectral-norm   4.44s 0.02 4.20s 0.16 4.51s
pidigits   4.69s 0.09 4.44s 0.05 4.61s
fasta   5.07s 0.46 4.84s 0.02 5.13s
chameneos-redux   5.84s 0.46 5.70s 0.48 5.65s
mandelbrot   7.93s 0.23 7.99s 0.01 7.02s
k-nucleotide   8.09s 0.28  --   --  8.05s
regex-dna   8.65s 0.27  --   --  8.61s
binary-trees   10.54s 0.28 7.66s 0.16 9.08s
fannkuch-redux   16.89s 1.32 17.26s 0.10 17.38s
nbody   22.43s 0.00 22.41s 0.00 22.50s
binary-trees-redux   34.15s 0.39 33.93s 0.31 33.38s

The largest and most obvious effects of bytecode loading and dynamic optimization can be seen with the meteor-contest program which only runs for a fraction of a second.

A more sophisticated way to make JVM timings following warmup iterations is to use JMH, see "Java Microbenchmark Harness (the lesser of two evils)" pdf.

"1.8.0" Java HotSpot(TM) 64-Bit Server VM
  Mode Samples Mean Mean error
spectralnorm.testMethod   ss 65   4.181 0.008
nbody.testMethod   ss 65   22.462 0.001

But please don't just assume those warmed-up timings will be a whole lot faster for the JVM programs shown here, at the workloads shown here.

Revised BSD license

  Home   Conclusions   License   Play