Created
May 23, 2011 22:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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). ??