Running JMH Runner from inside the source code?

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Feb 3 03:20:57 PST 2014


On 02/03/2014 03:15 PM, Behrooz N wrote:
> 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();
>     }

You can, if your IDE compiles the classes and invokes the annotation
processors along the way -- this will generate the microbenchmark list.
My IntelliJ IDEA does that perfectly well. Other IDEs may require
calling "mvn compile" before invoking the 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?

Come again? You generally need a full compile session for the project
holding your benchmarks, as this will generate the microbenchmark list.
After that, you may invoke the JMH in any way you want.

-Aleksey.


More information about the jmh-dev mailing list