JPerf 2.0

andygrove   November 9, 2014   1 Comment on JPerf 2.0

For those who don’t know, JPerf is a simple performance and scalability testing library for Java. It’s like JUnit but for performance.

This morning, I re-implemented JPerf from scratch using Java 8, making use of lambda functions to simplify usage, and making better use of java.util.concurrency. Here is a graph showing the current performance of a “no-op” test for the 2.0.0 release compared to the 1.3.1 release.

jperf2
The difference in performance is staggering. This is because I am no longer using ‘synchronized’ or ‘volatile’ keyword to share state between the test threads and the main thread, both of which cause the thread to have to synchronize with main memory, which is costly in terms of performance. I am now using AtomicLong to track counters in each thread instead and AtomicBoolean to implement a mechanism to stop the test threads.

The programmatic use of JPerf now looks like this:

It is also possible to run JPerf from the command-line. I used Apache CLI to provide a professional looking command-line interface.

By default, output is to stdout in this format:

It is easy to specify custom output formatters as well. For example, to use the CSV formatter:

This produces the following output, which can easily be loaded into a spreadsheet. You could also provide your own implementation of the ResultWriter interface to write to any other format.

The source code is available in github, here: https://github.com/andygrove/jperf

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

One thought on “JPerf 2.0

  1. andygrove Post author

    In my original results, the performance degraded with a higher number of threads. This turned out to be a simple bug where it was starting more test threads than intended and this is fixed now and the graph in the post has been updated.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *