Java Unit Benchmark Framework
Clone or download


JBenchX - Java Unit Benchmark Framework

JBenchX is a framework to write mirco benchmarks for your Java(tm) classes as easily
as you write unit tests using the well-known JUnit framework.



Example Benchmark to test how long it takes to generate a truely random integer:


import org.jbenchx.annotations.*;

public class Example {
  private SecureRandom fRandom;

  public Example() throws Exception {
    fRandom = SecureRandom.getInstance("SHA1PRNG");
  public int random() {
    return fRandom.nextInt();

Example Output:

Initializing Benchmarking Framework...
Performing 1 benchmarking tasks..
[0]	Example.random!.......*..	268ns

Eclipse Plug-in

There is an Eclipse plug-in available for JBenchX. This update site is located

Important note to Eclipse users: Before you can write JBenchX bechmarks in 
Eclipse you need to add the JBenchX library to the classpath! You can do this
easily by opening the Properties of your project, selecting the Java Build Path
page, chosing the Libraries tab and adding the JBenchX libraries with the
"Add Library..." command.

JBenchX's Philosophy

* Make it easy to write small benchmarks.
* Express everything in Java. 
* Use Java annotations to configure benchmarks.
* Make benchmarking run as fast as possible to get meaningful results.
* Use many iterations per run to make timings accurate.
* Use multiple runs and take the fastest.
* Monitor class recomiplation and garbage collection.
* Tell the user to cast a critical eye over the given benchmark results.