Nov 30

JVM Choice Matters (a lot!)

I’m one of the lucky folk who was able to obtain a Raspberry Pi Zero for $5. Originally this was going to be an article reviewing the Pi Zero to see how much of a difference the overclocking really makes. That and my impressions of the Zero will be in a later post.

TL;DR: The choice of JVM makes an enormous difference in how code runs on a machine. Oracle Java outperforms OpenJDK by a considerable margin in the following test.

The test consists of 3 Raspberry Pi computers:

  • Pi B+
  • Pi 2B
  • Pi Zero

I am using a 4.1.18 kernel, as opposed to the 3 series kernel from last March.

I’m using the same code as I did for Pi on a Pi for Pi Day — it’s single threaded and does not need a garbage collection. These two facts remove a lot of differences/advantages between the competitors.

I discovered the disparity first by running the code with OpenJDK 8. It was ridiculously slow. I thought, at first, it might be a difference with changing two variables, so I tried again with OpenJDK 7. The results in this case were much better. Remembering that Oracle’s JDK showed promise, I tried again — that time I had the best results.

All of the times below are user time.

Number of Terms OpenJDK 8 OpenJDK 7 Oracle Java 8
2B B+ Zero 2B B+ Zero 2B B+ Zero
1000 0m0.720s 0m1.500s 0m1.400s 0m0.580s 0m1.300s 0m1.340s 0m0.760s 0m1.580s 0m1.490s
10000 0m0.700s 0m1.500s 0m1.500s 0m0.610s 0m1.360s 0m1.270s 0m0.740s 0m1.520s 0m1.510s
100000 0m0.830s 0m1.630s 0m1.530s 0m0.640s 0m1.290s 0m1.340s 0m0.790s 0m1.620s 0m1.520s
1000000 0m1.870s 0m2.690s 0m2.630s 0m0.880s 0m1.590s 0m1.650s 0m0.900s 0m1.690s 0m1.660s
10000000 0m12.130s 0m13.030s 0m12.970s 0m3.180s 0m4.530s 0m4.510s 0m1.890s 0m2.770s 0m2.750s
100000000 1m54.470s 1m57.200s 1m56.330s 0m26.390s 0m33.690s 0m33.410s 0m11.850s 0m13.620s 0m13.520s
1000000000 19m21.700s 19m17.290s 19m9.770s 4m20.080s 5m25.040s 5m23.070s 1m51.660s 2m2.240s 2m1.590s

If you notice, the first several sized tests are all around the same time — there is a startup cost which is pretty much constant. Additionally, since the code is single threaded, the additional cores aren’t really making much difference.

So, OpenJDK 8 is approximately 10 times slower than Oracle JDK on the Raspberry Pi. Ouch! OpenJDK 7 isn’t quite so bad, but it’s still over 2 times slower.

I think I know which one I’ll be using…

1 ping

  1. Pi on a Pi for Pi Day » Ramblings

    […] EDIT: The metrics below are skewed. Not all JVM’s are created equal. For updated metrics on the Pi, please see JVM Choice Matters (a lot!). […]

Leave a Reply

%d bloggers like this: