Reputation: 193
Suppose I have a JMH test with two parameters:
@Param( { "1", "2", 4", "8", "16" } )
int param1;
@Param( { "1", "2", 4", "8", "16" } )
int param2;
Is there an idiomatic way to add a constraint on the parameters, e.g. only to benchmarks for param1 < param2
?
Throwing an exception from an @SetUp works, but adds noise to the output.
Upvotes: 4
Views: 774
Reputation: 18857
Nope, not at this point. If you feel the annotations are constraining, you can always fall back to the API. There, you can do something like:
for (int p1 = 1; p1 <= 16; p1 *= 2) {
for (int p2 = 1; p2 <= p1; p2 *= 2) {
Options opt = new OptionsBuilder()
...
.param("param1", p1)
.param("param1", p2)
.build();
RunResult r = new Runner(opt).runSingle();
... put r somewhere to process
}
}
(Maintainer's perspective: it does not seem worthwhile to wind up a full-fledged annotation-based DSL for JMH, it's just simpler to let users code their advanced scenarios in Java).
UPD: Come to think about it, you can probably encode both parameters into a single @Param
, if you want to stay with the annotation-only way.
Upvotes: 4