Feature request: extend OptionsBuilder to have OptionsBuilder.param(class, name, value) method

Alex Averbuch alex.averbuch at neotechnology.com
Wed Aug 31 09:06:25 UTC 2016


TL;DR;

Problem:
  > parameter names set via OptionsBuilder.param(name,value) are set
globally, i.e., there is no way to set a @Param value for a field in a
particular class.

Request:
  > Either, add method to OptionsBuilder that allows for values to be set
on fields in particular classes, e.g.,
OptionsBuilder.param(class,"name",value)
  > Or, support the setting of fully qualified names, e.g.,
OptionsBuilder.param("package.class.name",value)

--- My specific problem ---

For a benchmark suite I've written I have my own runner, using
OptionsBuilder to set param values (taken from a config file).
There are many @Benchmarks in this suite.
Many benchmarks are similar, but sufficiently different that it makes sense
to put them in different (@State) classes.
Consequently, there are many classes, each containing multiple benchmark
methods.
Because benchmark classes contain similar benchmarks their @Params often
have the same names.

For example:

public class BenchmarkClass1
{
    @Param( {} )
    public int paramName;

    @Benchmark
    public int doSomething()
    {
        return soSomethingWith(paramName);
    }
}

public class BenchmarkClass2
{
    @Param( {} )
    public int paramName;

    @Benchmark
    public int doSomethingVerySimilar()
    {
        return soSomethingWith(paramName);
    }
}

My current solution is to add class name prefixes to parameter names.
For Example:

public class BenchmarkClass1
{
    @Param( {} )
    public int BenchmarkClass1_paramName;

    @Benchmark
    public int doSomething()
    {
        return soSomethingWith(BenchmarkClass1_paramName);
    }
}

I am well aware of the shame I should feel for doing this -- I feel that
shame.
If I've overlooked some feature in JMH that could solve this pain point.
please point me to it.
If not, how do others get around this limitation?

Cheers,
Alex


More information about the jmh-dev mailing list