Skip to content

Instantly share code, notes, and snippets.

@apangin
Created October 18, 2015 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apangin/9da33d91bd6e59324b1b to your computer and use it in GitHub Desktop.
Save apangin/9da33d91bd6e59324b1b to your computer and use it in GitHub Desktop.
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