Skip to Main Content

Strange performance problem with R28.2.3 v R27.6.5

maumoondoggieJun 6 2012
I was looking at the performance of StringBuffer/StringBuilder append and came across a strange problem which I believe is a problem in the optimisation on JRockit.

So, if I run the following TestCode1.java each version takes this long to complete :
(This is a 8 core machine and the process consumes 100% CPU)
R27.6.5 1.5.0_19 32bit linux - 15s
R28.2.3 1.5.0_34 32bit linux - 25s

If I get rid of the Integer conversion and use a string (TestCode2.java) then I get these times :
R27.6.5 1.5.0_19 32bit linux - 14s
R28.2.3 1.5.0_34 32bit linux - 13s

I suspect that there is some problem in the optimisation on JRockit of Integer.toString(int) possibly.

If I run the TestCode1.java again using the -Xnoopt option then I get :
R27.6.5 1.5.0_19 32bit linux - 44s
R28.2.3 1.5.0_34 32bit linux - 44s

However, if I simply call Integer.toString(int) myself I don't see the same issue :
R27.6.5 1.5.0_19 32bit linux - 15s
R28.2.3 1.5.0_34 32bit linux - 15s

Any JRockit internal engineers that want to have a look at it?

maumoon

===== TestCode1.java =====
public class TestCode1 {

public static final String PREFIX = "line";

public static String doTest(int number) {
StringBuilder sb = new StringBuilder(140);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
return sb.toString();
}

public static void main(String[] args) {
long start = System.currentTimeMillis();
for(int count=0; count<20000000; count++) {
doTest(count);
}
System.out.println("Time taken: "+(System.currentTimeMillis()-start)+"ms");
}
}

===== TestCode2.java =====
public class TestCode2 {

public static final String PREFIX = "line";

public static String doTest(String number) {
StringBuilder sb = new StringBuilder(140);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
sb.append(PREFIX).append(number);
return sb.toString();
}

public static void main(String[] args) {
long start = System.currentTimeMillis();
for(int count=0; count<20000000; count++) {
doTest(" suffix");
}
System.out.println("Time taken: "+(System.currentTimeMillis()-start)+"ms");
}
}

===== TestInteger.java =====
public class TestInteger {
public static String doTest(int count) {
return Integer.toString(count);
}

public static void main(String[] args) {
long start = System.currentTimeMillis();
int count = 0;
while(++count<200000000) {
doTest(count);
}
System.out.println("Integer.toString(count) "+(System.currentTimeMillis()-start)+"ms");
}
}
Comments
Post Details
Added on Jun 6 2012
0 comments
196 views