Created
October 18, 2015 15:21
-
-
Save apangin/9da33d91bd6e59324b1b to your computer and use it in GitHub Desktop.
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
package bench; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
@State(Scope.Thread) | |
public class InliningBenchmark { | |
static volatile int value = 20; | |
@Benchmark | |
public int inlineStaticSmall() { | |
return smallMethod(); | |
} | |
@Benchmark | |
public int inlineVirtualLarge() { | |
return largeMethod(); | |
} | |
public static int smallMethod() { | |
if (value == 10) { | |
return 111; | |
} else if (value == 20) { | |
return 222; | |
} else { | |
return 0; | |
} | |
} | |
public int largeMethod() { | |
if (value == 10) { | |
return 111; | |
} else if (value == 20) { | |
return 222; | |
} else if (value == 30) { | |
return 333; | |
} else if (value == 40) { | |
return 444; | |
} else if (value == 50) { | |
return 555; | |
} else if (value == 60) { | |
return 666; | |
} else if (value == 70) { | |
return 777; | |
} else if (value == 80) { | |
return 888; | |
} else if (value == 90) { | |
return 999; | |
} else { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment