Running JMH Runner from inside the source code?

Behrooz N nobeh5 at gmail.com
Mon Feb 3 03:15:42 PST 2014


Thanks for the complete explanation.

To finalize an understanding for me: so I cannot simply inside my IDE (e.g.
eclipse), right-click on the following piece and say "Run as Java
Application"

    public static void main(String[] args) throws RunnerException {
        Options options = new
OptionsBuilder().include(".*").exclude(".*openjdk.*")
                .warmupIterations(1000).measurementIterations(100000)
                .verbosity(VerboseMode.EXTRA).build();
        new Runner(options).run();
    }

Based on the Maven archetype, it is required that I build an artifact from
my artifact that may have the above main method and then run the benchmark
through above that is actually a simpler version. Is this correct?


On Mon, Feb 3, 2014 at 11:54 AM, Aleksey Shipilev <
aleksey.shipilev at oracle.com> wrote:

> 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/
>



-- 
-- Behrooz Nobakht


More information about the jmh-dev mailing list