Benchmarking Java speed on the Raspberry Pi

In a similar vein to the python benchmarking experiment I did previously, I’m also interested in Java performance on the Raspi. For this, I used the code Gibbs.java from my old language benchmarking blog post, which for completeness is given below:

import java.util.*;
import cern.jet.random.tdouble.*;
import cern.jet.random.tdouble.engine.*;
class Gibbs{
    public static void main(String[] arg)
    {
        int N=50000;
        int thin=1000;
        DoubleRandomEngine rngEngine=new DoubleMersenneTwister(new Date());
        Normal rngN=new Normal(0.0,1.0,rngEngine);
        Gamma rngG=new Gamma(1.0,1.0,rngEngine);
        double x=0;
        double y=0;
        System.out.println("Iter x y");
        for (int i=0;i<N;i++) {
            for (int j=0;j<thin;j++) {
                x=rngG.nextDouble(3.0,y*y+4);
                y=rngN.nextDouble(1.0/(x+1),1.0/Math.sqrt(2*x+2));
            }
            System.out.println(i+" "+x+" "+y);
        }
    }
}

This relies on the Parallel COLT library, which must be in the Java classpath for compilation and execution. To start with I ran it on my fast Intel i7 laptop (running 64bit Ubuntu 12.04), where it took 11.4 seconds. Next I ran it on my Intel Atom based netbook (running 32bit Ubuntu), where it took 63.1 seconds. This is around 5 times slower, as I would expect. In both cases, I’m using OpenJDK 1.6. Note that the code can be compiled and run as follows:

% javac Gibbs.java
% time java Gibbs > /dev/null

As I’ve shown in a previous post, Raspbian has much better floating point performance than other Debian-based distributions running on the Raspberry Pi. So obviously that’s what I’ve used for benchmarking purposes. I’ve started off running the code using the standard java package, openjdk-6-jre. Running with that JVM took 65 minutes 19 seconds – more than 60 times slower than my netbook! This is very disappointing, but is due in part to the fact that there is no JIT in the standard OpenJDK JVM for ARM. However, this question on RaspberryPi.SE pointed me to the package icedtea-6-jre-cacao, which contains a JVM with JIT. This is reported to lead to impressive speed-ups on certain codes. Running my code with that package (using the -cacao option) caused the JVM to crash… So somewhat analagously with my python experiment, it seems that JVMs on the Pi are much less mature than on Intel (which isn’t too surprising, of course). There could also be fundamental reasons (eg. speed of memory access) why byte-code interpreted languages will never be as fast on the Pi relative to Intel, but that is difficult to assess without a JIT-enabled JVM. Right now, it seems that Java doesn’t run that much faster than Python on the Pi. I’ve also seen reference to people getting better performance by using gcj-jdk to compile to native code ahead of time (rather than using a JIT JVM). This is possible, but typically not straightforward, and GCJ isn’t a very active project any more, so doesn’t seem like an attractive option to me. I’ve also seen it suggested that OpenJDK 7 is faster than 6 on the Pi, but openjdk-7-jre doesn’t yet seem to have made it into the Raspbian repos…

So at least for the time being, it seems that C is the best way to get good floating point intensive performance out of the Pi. However, it seems likely that if someone were to produce a good ARM-optimised, JIT-enabled (not-too-buggy) JVM for the Pi, there is room for an order of magnitude performance improvement relative to the currently available JVMs. It’s certainly worth keeping an eye on the cacao JVM to see if its stability improves. This would be great, but I’m not holding my breath… In the meantime, there doesn’t appear to be anything obviously better and faster than the OpenJDK JVM, so that currently seems like a reasonable choice of JVM for Java deployment on the Pi, and OpenJDK 7 will hopefully be a bit faster than 6, when it appears in the Raspbian repos, even if the JIT doesn’t work. It’s early days, so it’s quite possible that the whole Java-on-the-Pi situation will look a lot better in a few months time… I hope so!

Advertisements

Published by

darrenjw

I am Professor of Stochastic Modelling within the School of Mathematics & Statistics at Newcastle University, UK. I am also a computational systems biologist.

One thought on “Benchmarking Java speed on the Raspberry Pi”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s