I'm trying to compare the performance of the two main Java implementations: Oracle and IBM on running the following test:
public class HarmonicSeriesTest {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
final int limit = 20;
double sum = 0.0;
long n = 0;
while (sum < limit) {
n++;
sum += 1.0 / n;
}
long duration = System.currentTimeMillis() - startTime;
System.out.printf("n is %d\n", n);
System.out.printf("Executed in %d miliseconds\n", duration);
}
}
By running the above code with:
- IBM JRE 1.8.0
java version "1.8.0" Java(TM) SE Runtime Environment (build pwa6480sr3fp22-20161213_02(SR3 FP22)) IBM J9 VM (build 2.8, JRE 1.8.0 Windows 10 amd64-64 Compressed References 20161209_329148 (JIT enabled, AOT enabled) J9VM - R28_20161209_1345_B329148 JIT - tr.r14.java.green_20161207_128946 GC - R28_20161209_1345_B329148_CMPRSS J9CL - 20161209_329148) JCL - 20161213_01 based on Oracle jdk8u111-b14
- Oracle JRE 1.8.0_131
java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
- Sun JRE 1.5.0_22
java version "1.5.0_22" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)
I consistently get the following results:
- IBM JRE 1.8.0 Compiler compliance level 1.8
n is 272400600 Executed in 1024 miliseconds
- Oracle JRE 1.8.0_131 Compiler compliance level 1.8
n is 272400600 Executed in 2002 miliseconds
- Sun JRE 1.5.0_22 Compiler compliance level 1.5
n is 272400600 Executed in 1506 miliseconds
As you can see, the Oracle JRE is slower by 100% compared to IBM JRE and 25% compared to Sun JRE. The gap between Oracle and IBM implementations is huge, also Oracle JRE looks like a regression over Sun JRE.
Does anyone have an explanation why is the 'official' implementation of Java so slow?
I have no interest in using JMH since I don't want to benchmark anything.
Bellow is the hardware configuration I used for testing: