Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No matching benchmarks" when running JMH from main in eclipse

I wanted to try out the new feature of JMH by running it as Java Application in eclipse. I imported and built jmh-samples project. Compiled classes ended in /jmh-samples/target/generated-sources/annotations, there are several JARs in /target/ and running microbenchmarks.jar from command line works as usual.

However when I execute main I always get

No matching benchmarks. Miss-spelled regexp?

Any ideas? I am using version 0.3

like image 911
Kranach Avatar asked Jan 28 '14 05:01

Kranach


People also ask

How do you run JMH benchmarks?

There are two ways to run the JMH benchmark, uses Maven or run it via a JMH Runner class directly. 3.1 Maven, package it as a JAR and run it via org. openjdk.

What are JMH benchmarks?

JMH Benchmark Modes Measures how long time it takes for the benchmark method to execute, including max, min time etc. Measures how long time a single benchmark method execution takes to run. This is good to test how it performs under a cold start (no JVM warm up).


3 Answers

I was also facing the same problem, and I followed the tutorial here. That solved the issue.

Below are the steps I took:

  • I used the code from the tutorial AS-IS to understand how it works.

  • Then I just did mvn clean and install

  • I saw all set of classes being created in target -> annotations -> <package path> -> generated
  • Then I ran the BenchmarkRunner main() class and this worked.
like image 76
ctimus Avatar answered Sep 21 '22 08:09

ctimus


jmh-dev@ is a better way to communicate this with the developers.

Few things to try:

  1. Hijacking Main is probably not a good idea. Use Java API instead, like this sample.
  2. Use -v extra to debug the pattern matching: either the filter regexp is incorrect, or there are no benchmarks to run.
  3. If the regexp is incorrect, fix it.
  4. If there are no benchmarks to match against, then there is a chance resources are not generated and/or picked up properly. Make sure target/classes/ is also available on classpath.
like image 3
Aleksey Shipilev Avatar answered Oct 11 '22 22:10

Aleksey Shipilev


Okay, so looks like by default jmh looks for generated classes under META-INF/Microbenchmarks, which maven build puts under root of the project. However root of the eclipse project is not on the classpath, so executing it in IDE results in "no benchmarks found".

I got it running following way:

  1. mvn clean package (using external maven installation, not embded in eclipse)
  2. Right-click on jmh-samples project, select "Build Path -> Use as a source folder"
  3. You can now run any of the benchmarks from jmh-samples as Java Application in eclipse

On the downside you get like 1000+ "errors" in Problems view, since eclipse gets confused with auto-generated files, but oh well, at least it works.

like image 3
Kranach Avatar answered Oct 11 '22 23:10

Kranach