Running JMH Runner from inside the source code?

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Feb 3 02:54:25 PST 2014


On 02/03/2014 02:47 PM, Behrooz N wrote:
> The dependency on jmh-samples is only for studying intentions to get to
> know better how to use JMH.

But you don't need to depend on it to make your own benchmarks :)

> Now, this rises another questions for me. I noticed how
> META-INF/MicroBenchmarks is used at JMH. So, my question is that do I
> need to also have such a file in my resources folder? This files seems
> to be using a specific format which I do not find any document for. 

META-INF/MicroBenchmarks holds the benchmark lists and settings. It is
mangled in the internal JMH format, and should be opaque to users. It is
generated during the compilation by @GenerateMicroBenchmark processor,
and used by JMH runners to determine what benchmarks are available and
what default settings they bear. I can't think about the use case where
users should care about creating/modifying this file on their own.

> And, my understanding so far is that I only need to have jmh-core and
> use Runner API, is that correct?

Yes. jmh-core contains the API. At this point, it also contains the
org.openjdk.jmh.Main method. Hence, if you mix the jmh-core into your
project, you have both API and CLI runners.

If you follow the archetype advice on the JMH page [1], you will get the
scratch benchmark project with all the proper dependencies set up.

-Aleksey.

[1] http://openjdk.java.net/projects/code-tools/jmh/


More information about the jmh-dev mailing list