advice on usage of jmh

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Sep 16 20:49:13 UTC 2015


Hi,

These questions should normally go to StackOverflow -- those guys even
have a "jmh" tag, and many power JMH users are answering questions there.

On 09/16/2015 09:34 PM, Jochen Theodorou wrote:
> My problem is, that when ever I try to rewrite this into something using
> JMH the code size explodes. Instead of a single generic method for
> containsKey I end up with one for each map type, plus.. 

I can't see a problem with selecting an implementation, if they all
implement the same interface, e.g:

http://hg.openjdk.java.net/code-tools/jmh/file/f2d57d49d36b/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_35_Profilers.java#l71

The same thing could be done for selecting a dataset you are walking.

> then I thought I could use enums to make this more easy, but then I
> found out that @Param does not allow me to select the enum values I
> want to go through.

Using enums may be cleaner and more resilient against typos. What does
it mean "@Param does not allow to select the enum values"? This works
perfectly well:

@State(Scope.Thread)
public class EnumBenchTest {

    public enum MyMode {
       MODE1,
       MODE2
    }

    @Param({"MODE1"})
    private MyMode mode;

    @Benchmark
    public void test() {
        // intentionally left blank
    }
}


Thanks,
-Aleksey



More information about the jmh-dev mailing list