Skip to content

Instantly share code, notes, and snippets.

@rdp
Created May 23, 2011 22:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/987751 to your computer and use it in GitHub Desktop.
Save rdp/987751 to your computer and use it in GitHub Desktop.
example file that seems to get slower when used with hotspot JVM. Us
/* use like
$ javac Go2.java
$ java -client Go2
$ java -server Go2
*/
public class Go2 {
public static class A {
public Object go(A arg1) {
if (arg1 != null) {
return arg1.go(null);
}
else {
return null;
}
}
}
public static void go2(A in1, A in2) {
in1.go(in2);
}
static A in3;
static A in4;
public static void go3() {
in3.go(in4);
}
public static void main(String[] args) {
for (int x1 = 0; x1 < 25; x1++) {
A in = new A();
long start = System.nanoTime();
long count = 0;
for (int x = 0; x < 10000000; x++) {
in.go(in);
}
System.out.println("for loop took: " + (System.nanoTime() - start)/1000000);
in3 = in;
in4 = in;
start = System.nanoTime();
count = 0;
for (int x = 0; x < 10000000; x++) {
//go2(in, in); // either of these two lines don't seem be faster, under server JVM
go3();
}
System.out.println("method call took: " + (System.nanoTime() - start)/1000000);
}
}
}
@rdp
Copy link
Author

rdp commented May 26, 2011

I guess my real hope would have been "is there some setting I can tweak so that the second loop takes as long as the first loop [0ms] since that it really fast and I would love to have the speedup" (apparently hotspot is smart, but that not smart, unfortunately). ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment