Running benchmark with main method from the generated jar

Luis IBANEZ luis.ibanez at univ-nantes.fr
Wed Apr 2 12:30:39 UTC 2014


Hi Aleksey,

>
> I say like this:
....
>          Options baseOpts = new OptionsBuilder()
> +                .parent(new CommandLineOptions(args))
>                  .include(".*" + JMHSample_25_API_GA.class.getName() +
> ".*")

When I add the "parent(new CommandLineOptions(args)" line, if i do

java -cp microbenchmarks.jar mypackage/mysubpack/MyClass -i 5 -wi 5

It does take in account the -i and -wi switches, but, it ignores that I
want to execute "MyClass" and starts executing all benchmarks with these
parameters, like if i were using the normal "java -jar microbenchmark.jar"
call without filtering.

>>   2/ I also tried to set other parameters (path to the data used), but I
>> need to hardwire the location of the settings file as it seems that the
>> method annotated as Trial is executed even before the main (I thought it
>> was injected just after the call to Runner.run)
>
> @Setup-s should be executed after main(). Something wicked happens in
> your code :)

The thing is that I don't know how to pass arguments to the Setup methods,
this means that I make the Properties a static class attribute, to be able
to load it in the main and use it in the SetUp method... Maybe this is the
problem, I'm attaching a code sample.


> Hi Luis,
>
> On 04/02/2014 01:58 PM, Luis IBANEZ wrote:
>> But that means I lose all the nice command line options provided with
>> the
>> jar.
>
> I assume you want the same CLI interface JMH offers for other benchmarks?
>
>> I tried using a Properties file, but:
>>   1/ The option parsing is up to me (I still have not checked how to
>> reuse
>> whatever option parsing jmh uses though)
>
> See below.
>
>>   2/ I also tried to set other parameters (path to the data used), but I
>> need to hardwire the location of the settings file as it seems that the
>> method annotated as Trial is executed even before the main (I thought it
>> was injected just after the call to Runner.run)
>
> @Setup-s should be executed after main(). Something wicked happens in
> your code :)
>
>> Short version of the question: How do I execute code sample [0] from the
>> generated jar while maintaining the settings control?
>
> I say like this:
>
> diff -r 3b57fecd61bf
> jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_25_API_GA.java
> ---
> a/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_25_API_GA.java
> Tue Apr 01 21:53:13 2014 +0400
> +++
> b/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_25_API_GA.java
> Wed Apr 02 14:07:30 2014 +0400
> @@ -31,6 +31,8 @@
>  import org.openjdk.jmh.logic.results.RunResult;
>  import org.openjdk.jmh.runner.Runner;
>  import org.openjdk.jmh.runner.RunnerException;
> +import org.openjdk.jmh.runner.options.CommandLineOptionException;
> +import org.openjdk.jmh.runner.options.CommandLineOptions;
>  import org.openjdk.jmh.runner.options.Options;
>  import org.openjdk.jmh.runner.options.OptionsBuilder;
>  import org.openjdk.jmh.runner.options.VerboseMode;
> @@ -82,11 +84,13 @@
>       * performance. Try to run the sample and see if it improves
> performance.
>       */
>
> -    public static void main(String[] args) throws RunnerException {
> +    public static void main(String[] args) throws RunnerException,
> CommandLineOptionException {
>          // These are our base options. We will mix these options into the
>          // measurement runs. That is, all measurement runs will inherit
> these,
>          // see how it's done below.
> +
>          Options baseOpts = new OptionsBuilder()
> +                .parent(new CommandLineOptions(args))
>                  .include(".*" + JMHSample_25_API_GA.class.getName() +
> ".*")
>                  .warmupTime(TimeValue.milliseconds(200))
>                  .measurementTime(TimeValue.milliseconds(200))
>
> -Aleksey
>


More information about the jmh-dev mailing list