Getting "No benchmarks to run"

David Karr davidmichaelkarr at gmail.com
Sat Dec 2 05:22:10 UTC 2017


I'm trying to compare the performance of two methods for operating on
a map with populated random data.

The following is my current benchmark class:
--------------------------
@State(Scope.Benchmark)
public class Streams {
    private static final int    NUM_ELEMENTS    = 100;

    private Map<String, Long>    scores;

    public static void main(String[] args) {

        Streams streams = new Streams();
        streams.doit();
    }

    private void doit() {
        setup();
        System.out.println("scores[" + scores + "]");
    }

    public String randomString() { return RandomStringUtils.random(16); }
    public long randomLong() { return RandomUtils.nextLong(0L, 100L); }

    @Setup
    public void setup() {
        scores  = IntStream.range(0,
NUM_ELEMENTS).asLongStream().mapToObj(v ->
randomString()).collect(Collectors.toMap(Function.identity(), val ->
randomLong()));
    }

    @Benchmark
    public void measureGroupByScores1() {
        Streams.groupByScores1(scores);
    }

    public static Map<Long, List<String>> groupByScores1(Map<String,
Long> scores) {
        return scores.keySet().stream().collect(Collectors.groupingBy(scores::get));
    }

    @Benchmark
    public void measureGroupByScores2() {
        Streams.groupByScores2(scores);
    }

    public static Map<Long, List<String>> groupByScores2(Map<String,
Long> scores) {
        return scores.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue,
Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
    }
}

----------------

I'm using the Gradle JMH plugin (https://github.com/melix/jmh-gradle-plugin).

In this project, I also have another class with benchmarks, although
I'd prefer to only run the benchmarks in this "Streams" class for now.

Currently, when I run the "jmh" task, I get this (many lines elided):
-----------------
:compileJmhJava UP-TO-DATE
:processJmhResources NO-SOURCE
:jmhClasses UP-TO-DATE
:jmhRunBytecodeGenerator
Processing 16 classes from
C:\Users\<userid>\workspace\jsonpathexperiments\build\classes\java\jmh
with "reflection" generator
Writing out Java source to
C:\Users\<userid>\workspace\jsonpathexperiments\build\jmh-generated-sources
and resources to
C:\Users\<userid>\workspace\jsonpathexperiments\build\jmh-generated-classes
:jmhCompileGeneratedClasses
:jmhJar
Encountered duplicate path "enums/Enums$Thingie1.class" during copy
operation configured with DuplicatesStrategy.WARN
...
Encountered duplicate path "streams/generated/Streams_jmhType.class"
during copy operation configured with DuplicatesStrategy.WARN
...
Encountered duplicate path
"enums/generated/Enums_enumValuesLoop_jmhTest.class" during copy
operation configured with DuplicatesStrategy.WARN
...
Encountered duplicate path "streams/generated/Streams_jmhType.class"
during copy operation configured with DuplicatesStrategy.WARN
...
:jmh FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jmh'.
> A failure occurred while executing me.champeau.gradle.IsolatedRunner
   > Error during execution of benchmarks

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jmh'.
...
Caused by: No benchmarks to run; check the include/exclude regexps.
    at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:261)
    at org.openjdk.jmh.runner.Runner.run(Runner.java:206)
    at me.champeau.gradle.IsolatedRunner.run(IsolatedRunner.java:38)
    ... 12 more
--------------------

The "jmh" block in my build script is just this:
-------------
jmh {
    //verbosity = 'EXTRA' // Verbosity mode. Available modes are:
[SILENT, NORMAL, EXTRA]
    jvmArgs = ['-Djmh.ignoreLock=true']
    jmhVersion = '1.19'
    fork = 2
    duplicateClassesStrategy = 'warn'
    iterations = 40
    //include = ['Streams']
}

-------------

Not sure what's going on here.


More information about the jmh-dev mailing list