5

I want to measure the performance of Fibonacci function with JMH. but when compiling I get the following error:

Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList
    at jmh.core@1.34/org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:98)
    at jmh.core@1.34/org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:124)
    at jmh.core@1.34/org.openjdk.jmh.runner.Runner.internalRun(Runner.java:253)
    at jmh.core@1.34/org.openjdk.jmh.runner.Runner.run(Runner.java:209)
    at jmh.core@1.34/org.openjdk.jmh.Main.main(Main.java:71)
    at project/Mypackage.BenchmarkRunner.main(BenchmarkRunner.java:6)

I use IntelliJ IDEA I use openJDK 16

I tried to add in the Resources directory the folder and file /META-INF/BenchmarkList I have this error :

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

my main class who start the benchmark:

public class BenchmarkRunner {
    public static void main(String[] args) throws Exception {
        org.openjdk.jmh.Main.main(args);
    }

}

And the class with Fibonnaci methods whose performance I want to measure

public class TestClassMesurment {

    @Benchmark
    @BenchmarkMode(Mode.AverageTime)
    @Fork(value = 1)
    @Warmup(iterations = 2)
    @Measurement(iterations = 1)
    public void init() {

        fib(52);
        //fibbonaci(300);
    }

    static int fib(int n) {
        if (n<2) return 1;
        else return fib(n-1) + fib(n-2);
    }

    
    double fibbonaci(int n){
        double prev=0d, next=1d, result=0d;
        for (int i = 0; i < n; i++) {
            result=prev+next;
            prev=next;
            next=result;
        }
        return result;
    }
}
jaki hart
  • 95
  • 7

1 Answers1

3

/META-INF/BenchmarkList is generated automatically at compilation time, you don't need to create it manually. If this file is not created this usually means that annotation processing is off. Please turn it on.

Also the way you run the benchmark differs from the one specified in samples. Try to use that approach as well.

Sergey Tsypanov
  • 3,265
  • 3
  • 8
  • 34