Created
December 11, 2015 23:53
-
-
Save hussachai/45feb04219912b52704e 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
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Level; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
@BenchmarkMode({Mode.Throughput}) | |
public class TestSomethingInJava { | |
@State(Scope.Benchmark) | |
public static class TestState { | |
@Param({"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}) | |
public int arg; | |
public Test1 test1; | |
public Test1_1 test1_1; | |
public Test2 test2; | |
@Setup(value = Level.Invocation) | |
public void setup(){ | |
test1 = new Test1(); | |
test1_1 = new Test1_1(); | |
test2 = new Test2(); | |
} | |
} | |
public static class Test1 { | |
private int i; | |
public int getI() { | |
return i; | |
} | |
public void setI(int i) { | |
this.i = i; | |
} | |
} | |
public static class Test1_1 { | |
private int i; | |
public void kindoflikesetI(int i) { | |
this.i = i; | |
} | |
public int kindoflikegetI(){ | |
return i; | |
} | |
} | |
public static class Test2 { | |
public int i; | |
} | |
@Benchmark | |
public Test1 testInstantiate1(){ | |
return new Test1(); | |
} | |
@Benchmark | |
public Test2 testInstantiate2(){ | |
return new Test2(); | |
} | |
@Benchmark | |
public int testSetAndGet1(TestState state){ | |
state.test1.setI(state.arg); | |
return state.test1.getI(); | |
} | |
@Benchmark | |
public int testSetAndGet1_1(TestState state){ | |
state.test1_1.kindoflikesetI(state.arg); | |
return state.test1_1.kindoflikegetI(); | |
} | |
@Benchmark | |
public int testSetAndGet2(TestState state){ | |
state.test2.i = state.arg; | |
return state.test2.i; | |
} | |
public static Integer something(int i) { | |
return i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment