I use jmh(http://openjdk.java.net/projects/code-tools/jmh/ ) to benchmark some method. Also I have the set of parameters that I want to use as arguments to run this method. Is it possible to generate a method for the each particular parameter value (with @GenerateMicroBenchmark annotation)?
Now I use the similar implementation, but it isn't so convenient, because of I have to write a lot of uniform code by hand:
interface State {
int action();
void prepare();
}
class Method {
...;
toString() { return "State1_" + param; }
}
{
Method[] states;
curState = -1;
count = 0;
int[] params = {1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000};
for (int param: params) {
states[count++] = new Method(param);
}
}
@Setup(Level.Invocation)
public void prepareState() {
if (curState != -1) {
states[curState].prepare();
}
}
@GenerateMicroBenchmark
public int param_1000() {
curState = 0;
return states[curState].action();
}
@GenerateMicroBenchmark
public int param_2000() {
curState = 1;
return states[curState].action();
}
@GenerateMicroBenchmark
public int param_3000() {
curState = 2;
return states[curState].action();
}
...
@GenerateMicroBenchmark
public int param_12000() {
curState = 11;
return states[curState].action();
}