سؤال

I have some problem with using JMH.

So, I create an empty project in Intellij Idea, then in project structure add jmh-core jar file. Finally, try to run samples, for example

import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class JMHSample_01_HelloWorld {
    @GenerateMicroBenchmark
    public void wellHelloThere() {
        // this method was intentionally left blank.
    }
    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(".*" + JMHSample_01_HelloWorld.class.getSimpleName() + ".*")
                .forks(1)
                .build();

        new Runner(opt).run();
    }

}

but result is

No matching benchmarks. Miss-spelled regexp?
Use EXTRA verbose mode to debug the pattern matching.

Process finished with exit code 0

with using verbosity(VerboseMode.EXTRA)

No matching benchmarks. Miss-spelled regexp?
Benchmarks: 

Process finished with exit code 0

I tried to change output path to projectFolder\target\classes but nothing was changed. Then I looked at the source code in the debug mode and see that resource = "/META-INF/MicroBenchmarks",urls.hasMoreElements() is false and therefore benchmarks is empty. Then I saw at the samples jar file which has MicroBenchmarks file with information about tests and work well.

So, the question is what do I do wrong? Do I have to write information about test manually?

هل كانت مفيدة؟

المحلول

Please follow the instructions on JMH page to set up the benchmark project, namely:

"Make sure you tried these things before getting support: - Archetypes provide the golden build configuration. Try to generate the clean JMH benchmark project and transplant the benchmark there. This is important to try when upgrading to the newer JMH versions, since the minute differences in the build configurations may attribute to the failures you are seeing."

If you'd follow that, you will notice that you also need to add jmh-generator-annprocess as the dependency, and make sure it runs before you run any test.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top