Running benchmark with main method from the generated jar
Aleksey Shipilev
aleksey.shipilev at oracle.com
Wed Apr 2 15:24:54 UTC 2014
The attachments are stripped on this list, but I got a personal copy :)
See below:
On 04/02/2014 04:30 PM, Luis IBANEZ wrote:
> 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.
Of course it does not, because "parent" means "if the option is not set
here, ask the parent". In this case, we already overridden the parent
settings with our own. Scratch off the methods in OptionsBuilder chain
if you want some options to be overridable. (Maybe that will mean you
will get the only call to CommandLineOptions, so then you can feed it
straight to the Runner). If you want to provide default options, then
use annotations.
>>> 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.
This is a problem for the forked runs: your static is initialized in
host VM, but then JMH forks off the VM for measurement, and static is
obviously not initialized there. If you want to fix your example in a
simple way, read the properties in static initializer.
Or, use @Param. Any reason why you are not using it?
-Aleksey.
More information about the jmh-dev
mailing list