In working in java.math BigInteger, I discovered that hand inlining a method
called toLong() at least doubled my performance on Solaris. It seems that the symantec
JIT on windows can inline it. Shouldn't the Solaris JIT take care of this?
public class Inline {
private static int size = 1000;
public static void main(String[] args) throws Exception {
if (args.length >0)
size = Integer.parseInt(args[0]);
runInlineTest();
runCallTest();
}
private static final long toLong(int anInt) {
return anInt & 0xffffffffL;
}
private static long runInlineTest() {
long startTime = System.currentTimeMillis();
long c = 0;
for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++)
c += x & 0xffffffffL;
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
reportResult("Inlined test", "milliseconds", totalTime);
return c;
}
private static long runCallTest() {
long startTime = System.currentTimeMillis();
long c = 0;
for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++)
c += toLong(x);
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
reportResult("Method call test", "milliseconds", totalTime);
return c;
}
private static void reportResult(String label, String unit, long result) {
StringBuffer message = new StringBuffer(100);
message.append(label + " completed in " + result + " " + unit);
System.err.println(message);
}
}
called toLong() at least doubled my performance on Solaris. It seems that the symantec
JIT on windows can inline it. Shouldn't the Solaris JIT take care of this?
public class Inline {
private static int size = 1000;
public static void main(String[] args) throws Exception {
if (args.length >0)
size = Integer.parseInt(args[0]);
runInlineTest();
runCallTest();
}
private static final long toLong(int anInt) {
return anInt & 0xffffffffL;
}
private static long runInlineTest() {
long startTime = System.currentTimeMillis();
long c = 0;
for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++)
c += x & 0xffffffffL;
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
reportResult("Inlined test", "milliseconds", totalTime);
return c;
}
private static long runCallTest() {
long startTime = System.currentTimeMillis();
long c = 0;
for (int x = 0; x < size; x++)
for (int y = 0; y < size; y++)
c += toLong(x);
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
reportResult("Method call test", "milliseconds", totalTime);
return c;
}
private static void reportResult(String label, String unit, long result) {
StringBuffer message = new StringBuffer(100);
message.append(label + " completed in " + result + " " + unit);
System.err.println(message);
}
}