JMH provides a main-friendly API to run the benchmarks. It is based on defining the execution options which are more or less the options you can associate with a benchmark method (the one we saw in previous section with annotations) and a list of includes/excludes to select the classes/methods to run. Then, you pass these options to a runner and call its run() method:
final Collection<RunResult> results = new Runner( new OptionsBuilder() .include("com.packt.MyBenchmark") .build()) .run();
Here, we build a simple Options instance from the OptionsBuilder by including a benchmark class we want to include. Finally, we run it through the method with the same name as the runner, and collect the benchmark's results in a collection. ...