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

Entries by Robert Savage (60)

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.