@Param support for enum
Joe Kearney
mail at joekearney.co.uk
Fri May 23 16:19:00 UTC 2014
Hi,
Would you be interested in having @Param support enum fields? By
comparison, Caliper interprets @Param with no args to mean all enum values,
and (I think) loads specific named enum values @Param("FOO", "BAR").
Example below.
I've found this an easy way of describing the benchmark state space for
comparative tests of different implementations.
A workaround in jmh 0.7.3 is for the @Param("FOO", "BAR") field to be a
String, and set another field using Enum#valueOf() in a @Setup method. You
can make it use the whole set of enum values with OptionBuilder.param() and
some munging of the Enum#values() array, but there's no trivial way to do
it.
Most importantly, is there a reason that doing something like this would
contaminate the benchmark results? Is there a worry about the cost of the
extra method indirection? Perhaps that could be inlined if there's only one
enum value used per benchmark? I guess a lot of this could be benchmarked
as well.
Thanks,
Joe
@State(Scope.Benchmark)
public class BenchmarkWithEnums {
enum Implementation {
FOO {
@Override void doYourThang() {
System.out.println("Foo");
}
},
BAR {
@Override void doYourThang() {
System.out.println("Bar");
}
};
abstract void doYourThang();
}
@Param
private Implementation impl;
@GenerateMicroBenchmark
public void runTheBenchmark() {
impl.doYourThang();
}
}
More information about the jmh-dev
mailing list