GithubHelp home page GithubHelp logo

mp911de / microbenchmark-runner Goto Github PK

View Code? Open in Web Editor NEW
76.0 10.0 12.0 291 KB

JUnit extensions to launch JMH benchmarks from your IDE during development

License: Eclipse Public License 2.0

Java 100.00%

microbenchmark-runner's Introduction

Microbenchmark Runner

CI

Microbenchmark Runner is a JUnit (JUnit 4.12/JUnit 5.5) extension to launch JMH benchmarks using JUnit directly by using existing JUnit integrations.

Microbenchmark Runner is and what it isn't

This project is an aid during development to launch JMH benchmarks while developing these. Properly launching JMH benchmarks requires ideally the command line, an Uber-JAR and nothing else running to get good results.

During development time, we want quick turnaround times and an IDE that makes it simple to test-run benchmarks and that's what Microbenchmark Runner aims for.

⚠️ Do not use this launcher to run your benchmarks during CI or for actual measurements. Use it during development only. There are too many things that can blur actual results.

Here is a quick teaser of a what Microbenchmark Runner can do for you:

JUnit 4.x

@RunWith(Microbenchmark.class)
public class SimpleBenchmark {

    @State
    static class MyParameters {

        @Param({"1", "10", "100"}) // renders parametrized benchmarks as sub-tests
        String batchSize;
    }
    
    @Benchmark
    public void foo(MyParameters myParameters) {}
}

Decorate your JMH benchmark with @RunWith(Microbenchmark.class). Now you're able to leverage your IDE to start JMH benchmarks without fighting the command line.

JUnit 5.5.x

@Microbenchmark
public class SimpleBenchmark {

    @State
	static class MyParameters {

		@Param({"1", "10", "100"})  // renders parametrized benchmarks as sub-tests
		String batchSize;
	}

	@Benchmark
	public void foo(MyParameters myParameters) {
	}
}

Compatibility matrix

MBR Version JUnit 5 Version
0.2.x 5.5+
0.3.x 5.8+

Annotate your JMH benchmark with @Microbenchmark. Now you're able to leverage your IDE to start JMH benchmarks without fighting the command line.

Integrate it in your project

The easiest way is to use jitpack.io to include Microbenchmark Runner in your project:

Add the following repository to your pom.xml (when using Maven):

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

and one of the dependencies:

<dependency>
    <groupId>com.github.mp911de.microbenchmark-runner</groupId>
    <artifactId>microbenchmark-runner-junit4</artifactId>
    <version>${version}.RELEASE</version>
</dependency>
<dependency>
    <groupId>com.github.mp911de.microbenchmark-runner</groupId>
    <artifactId>microbenchmark-runner-junit5</artifactId>
    <version>${version}.RELEASE</version>
</dependency>

Configuration

You can configure the runner by using System Properties and Environment Variables to control behavior of the following parameters:

  • benchmarksEnabled (boolean, defaults to true) Controls whether benchmarks should be executed. Setting benchmarksEnabled=false can be useful for conditional execution of benchmarks.
  • benchmarkReportDir (File, defaults to none) Writes JMH benchmark results to this directory.
  • warmupIterations (integer, defaults to -1) Global override of warmup iterations. Uses @Warmup or JMH defaults if set to -1
  • warmupTime (integer, defaults to -1) Global override of warmup time. Uses @Warmup or JMH defaults if set to -1.
  • measurementIterations (integer, defaults to -1) Global override of measurement iterations. Uses @Measurement or JMH defaults if set to -1.
  • measurementTime (integer, defaults to -1) Global override of measurement time. Uses @Measurement or JMH defaults if set to -1.
  • forks (integer, defaults to -1) Global override of number of forks. Uses @Fork or JMH defaults if set to -1.
  • publishTo URL to configure one or more result publishers. jmh.mbr.core.ResultsWriterFactory implementations are discovered using the Java ServiceLoader mechanism. See Result Writers for further details.

Limitations

Microbenchmark Runner uses JUnit infrastructure to select Benchmarks to run and JUnit's progress reporting. Benchmarks are delegated to JMH's Runner Engine for execution. In consequence, JUnit annotations such as @Before, @BeforeEach, @BeforeAll, and others do not have any effect as they are not considered by the execution engine.

Result Writers

Microbenchmark Runner comes with pluggable support for result output. Results are published using the jmh.mbr.core.ResultsWriterFactory SPI.

Bundled publishers in microbenchmark-runner-extras are:

  • CSV reporting to System.out (enabled by default or with -Djmh.mbr.report.publishTo=sysout)
  • CSV reporting to a file (enabled with -Djmh.mbr.report.publishTo=csv:location/to/file)
  • Elasticsearch reporting (enabled with -Djmh.mbr.report.publishTo=elasticsearch://[username]:[password]@[host]:[port]/). The index name is controlled through an external property jmh.mbr.project.

Reporting Issues

Microbenchmark Runner uses GitHub’s integrated issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:

  • Before you log a bug, please search the issue tracker to see if someone has already reported the problem.
  • If the issue doesn’t already exist, create a new issue.
  • Please provide as much information as possible with the issue report, we like to know the version of Microbenchmark Runner that you are using, as well as your Operating System and JVM version.
  • If you need to paste code, or include a stack trace use Markdown ``` escapes before and after your text.
  • If possible try to create a test-case or project that replicates the issue.

Building from Source

If you want to try out the latest and greatest, Microbenchmark Runner can be easily built with the maven wrapper. You also need JDK 1.8.

$ ./mvnw clean install

License

Microbenchmark Runner is Open Source software released under the Apache 2.0 license.

microbenchmark-runner's People

Contributors

christophstrobl avatar dsyer avatar mp911de avatar sbrannen avatar sullis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microbenchmark-runner's Issues

Code copied from JUnit 5 must be released as EPL v2.0

I noticed that some of the code used to implement the microbenchmark-runner-junit5 module has been copied directly from the JupiterTestEngine internals in JUnit 5.

Since that code is published as EPL v2.0, the code in microbenchmark-runner-junit5 must also be published as EPL v2.0 instead of ASL v2.0.

Support for @Disabled

It would be neat to be able to exclude a class or a method temporarily with native JUnit tools, i.e. @Disabled in JUnit 5. Some of the code in #16 could be re-used.

Support for dynamically disabling tests

It's really useful sometimes to be able to disable a test at runtime, e.g. to skip tests that depend on a database if the database is not running. JUnit supports this through the use of Assumptions in @BeforeAll. PR #16 enables that but there are issues to do with static state.

Support for JUnit 5 tags

If you add a @Tag("benchmark") to a test class, it should be possible to exclude it. For example in Maven

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<excludeGroups>benchmark</excludeGroups>
				</configuration>
			</plugin>

Similar features exist in Eclipse, and no doubt in Gradle and IntelliJ. I normal (non benchmark) test can be exlcuded this way, but a @MicroBenchmark can not. Probably something to do with the implementation of the MicrobenchmarkEngine?

@Testable documentation is confusing

It's in the JUnit 5 section but that screenshot is not from a JUnit 5 class. Also, as far as I can tell, the @Testable annotation has absolutely no effect in Eclipse. Maybe change the screenshot, label it as "from IntelliJ", and mention explicitly that it helps there (and possibly not in other IDEs)?

Consider magically adding @Testable to JMH annotations

The README suggests that users manually add @Testable to benchmark methods.

That of course works; however, it would be nice if @Testable could be magically added to annotations such as @Benchmark transparently for the user -- for example, by modifying the byte code when such annotation classes are loaded, such as via a ClassFileTransformer.

Just a thought...

Report runtime exceptions to JUnit 5 runner.

When BenchmarkList is missing, then JMH throws a plain old RuntimeException while our JUnit 5 JmhRunner catches only RunnerException. We should catch these and notify all test plan children about the failure.

Add support for enums with @Param

Using @Param with enums derives the parameter values from the underlying enum. We should discover parameters as well to not require duplication of parameter values within the @Param(…) value array.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.