Contributions

Contributions are appreciated and used to host this site. Thank You for your support.

Feature Products
  • Raspberry Pi with Java: Programming the Internet of Things (IoT)
    Raspberry Pi with Java: Programming the Internet of Things (IoT)
  • Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
    Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
  • Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
    Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
  • Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
    Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
  • Getting Started with Raspberry Pi
    Getting Started with Raspberry Pi
  • Raspberry Pi User Guide
    Raspberry Pi User Guide
  • PiBrella LED Add On Board
    PiBrella LED Add On Board
  • Diversitech® WS-1 - Wet Switch Flood Detector
    Diversitech® WS-1 - Wet Switch Flood Detector
  • Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
    Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
  • Floodstop Washing Machine Valve Shutoff Kit
    Floodstop Washing Machine Valve Shutoff Kit
  • Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
    Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
  • Floodstop Individual Water Appliance Additional Water Sensor XS-01
    Floodstop Individual Water Appliance Additional Water Sensor XS-01
  • Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
    Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
  • Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
    Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
  • Metra 70-2002 Radio Wiring Harness for Saturn 00-05
    Metra 70-2002 Radio Wiring Harness for Saturn 00-05
  • Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
    Metra Reverse Wiring Harness 71-2002 for Select 2000-2005 Saturn Vehicles OEM Radio
Wednesday
Jan092013

Raspberry Pi - Java GPIO Frequency Benchmarks

Overview

In a previous article we covered Java runtime benchmarks using various JVMs.  Typical benchmark testing runs a series of varied task-based tests that attempt a wide array of coverage.  While these benchmark tests are great for generalized comparisons, I was curious how fast Java programs could update/write to the GPIO pins.  So this article is a very coarse-grained comparison on a single data point ... frequency of GPIO state changes.

Test Control Program

The test program used simply toggles the GPIO state between HI and LOW states as fast as it can by executing in a tight continuous loop.  Measurements were made using a digital oscilloscope (DSO) with the probe attached to GPIO pin 1.  

Additionally ...

OpenJDK 7 - ZeroVM

The following (single) snapshot reading was sampled from the test program while running it on the OpenJDK with the ZeroVM.  The GPIO pin was able to toggle states at a frequency of approximately 5 kHz.   


(click image to enlarge)

OpenJDK 7 - JAMVM

The following (single) snapshot reading was sampled from the test program while running it on the OpenJDK with the JamVM.  The GPIO pin was able to toggle states at a frequency of approximately 10.75 kHz, a notable improvement over the ZeroVM. 

(click image to enlarge)

OpenJDK 7 - Avian

I did attempt to run the test program using the Avian VM with OpenJDK; however the test program failed to start.  This error message was displayed on screen: "NATIVE (GpioInterrupt) ERROR; GpioInterrupt class not found."  It appears there is some issue loading the native JNI library.    

Oracle JDK SE 8 Preview for Linux/ARM (early access)

The following (single) snapshot reading was sampled from the same test program while running it using Oracle's JDK SE 8 Preview for Linux/ARM.  (Installing Oracle Java SE 8 (with JavaFX) Developer Preview for ARM)  The GPIO pin was able to toggle states at a frequency of approximately 153 kHz.  The VM really seems to make a difference here.  

(click image to enlarge)

Native C

For reference, I wanted to also include a native C test program for comparison.  The following readings were sampled from a native sample test program that implements the same test logic.  Access to the GPIO is accomplished using Gordon's WiringPi library.
The GPIO pin was able to toggle states at a frequency of approximately 7 MHz. 

(click image to enlarge)

Summary

Below is a summary of the results:

  • Java + OpenJDK 7 + ZeroVM = 5 kHz
  • Java + OpenJDK 7 + JamVM = 10.75 kHz
  • Java + OpenJDK 7 + Avian = Error; untested
  • Java + OracleJDK 8 (ea) + HotspotVM = 153 kHz
  • Java + OracleJDK 7u10 + HotspotVM = 161 kHz  (on soft-float Debian "Wheezy")
  • Native C + WiringPi = 7 MHz

If you are using Java and need hi-speed IO changes, then running on the Oracle JVM seems to be the best option at this time.  If you need really hi-speed IO, then you may want to think of pushing that work down into a native library.  It you require very precise timing, then please keep in mind that Linux is not a real time operating system. 

Hopefully this information sheds a little light, albeit on just one key metric, on how the different JVMs perform on the Raspberry Pi.    

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (8)

Great post, did you get a chance (or would you) try jdk 7?

Thanks.

Diego

January 11, 2013 | Unregistered CommenterDiego

Hi Diego,

I assume you mean Oracle's JDK 7u10 (on soft-float ABI) ?

I can test this and post the results this weekend.

Thanks, Robert

January 11, 2013 | Registered CommenterRobert Savage

yes, that's what I meant, thanks!

January 11, 2013 | Unregistered CommenterDiego

@ Diego,

Results for Oracle's JDK 7u10 (on soft-float ABI) are posted as a follow-up on the mail article.

Thanks, Robert

January 14, 2013 | Registered CommenterRobert Savage

Do you find it as disturbing as I do the stated performance in your tests of native C are so lacking compared to the interpreted languages of java and python. Further considering that java and python are written in C, it seems as though this is a red flag in the tests. Do you have any idea why there would be such disparity?

February 16, 2013 | Unregistered CommenterDave

@ Robert Thanks for posting an update!

February 16, 2013 | Unregistered CommenterDiego

@Dave,

The Native C + wiringPi test clocked in a 7 Megahertz while the Java and Python both clocked in at under 200 kilohertz. 1 megahertz = 1000 kilohertz, so the native C test outperformed all others by a significant factor.

-Robert

February 16, 2013 | Registered CommenterRobert Savage

My apologies. Yes, I guess i read too quick and missed the "M" vs "k" in the timing. Thanks for taking the time to post your results.

February 17, 2013 | Unregistered CommenterDave

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Raspberry Pi - Programming Pi-Face with Java & Pi4J | Main | Raspberry Pi - Install a Momentary Reset Button »