Saturday, January 19, 2013

Raspberry Pi Performance

With Groovy inside RPI, it is hard to resist running some performance tests after talking to my students. I know it will be unfair to compare RPI with a typical PC which costs more than 10-20 times however it will be interesting to see how far behind the RPI will be.
For that, I use 2 scenarios to evaluate the performance. The first scenario writes 2000 (by default) integers into a file. The second scenario reads the saved integers from the file and append them to a buffer. These scenarios exercise I/O, loop and string accumulation to a buffer. Each scenario runs 10 times, discards the best and worst performance then compute the average.

Raspberry Pi model B specs:
CPU: ARM11 700Mhz
RAM: 512MB
OS: Linux
Disk: 8GB class 4


PC specs:
CPU: Intel Core i5 2.6GHz Dual Core with hyper-threading technology
RAM: 16 GB
OS: Windows 7
Disk: 320GB 5400 RPM


Groovy Script to evaluate the performance: 
int maxFile = 10
int maxValue = args.length ? args[0].toLong() : 2000

long start
def l = []

// write to file
maxFile.times {
       File f = new File("perf${it}.txt")
       start = System.currentTimeMillis()
       maxValue.times {
              f << "${it}\n"
       }
       l << System.currentTimeMillis() - start
       println "Write to file: ${l[it]} ms"
}
println "Write to file avg:${(l.sum() - l.max() - l.min())/(maxFile - 2)} ms"

// read from file
l = []
StringBuilder sb
maxFile.times {
       sb = new StringBuilder(10000)
       File f = new File("perf${it}.txt")
       start = System.currentTimeMillis()
       f.eachLine {
              sb.append it
       }
       l << System.currentTimeMillis() - start
       println "Read from file: ${l[it]} ms, sb length:${sb.size()}"
}
println "Read from file avg:${(l.sum() - l.max() - l.min())/(maxFile - 2)} ms"

// delete file
maxFile.times {
       File f = new File("perf${it}.txt")
       f.delete()
}

RPI Results:
Write to file: 4368 ms
Write to file: 2063 ms
Write to file: 1938 ms
Write to file: 1969 ms
Write to file: 1938 ms
Write to file: 1950 ms
Write to file: 1941 ms
Write to file: 1918 ms
Write to file: 1927 ms
Write to file: 1917 ms
Write to file avg:1955.5 ms
Read from file: 309 ms, sb length:6890
Read from file: 120 ms, sb length:6890
Read from file: 52 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file: 39 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file: 38 ms, sb length:6890
Read from file avg:50.125 ms
 

PC Results:
Write to file: 1647 ms
Write to file: 1411 ms
Write to file: 1410 ms
Write to file: 1627 ms
Write to file: 1372 ms
Write to file: 1443 ms
Write to file: 1177 ms
Write to file: 2094 ms
Write to file: 1387 ms
Write to file: 1206 ms
Write to file avg:1437.875 ms
Read from file: 16 ms, sb length:6890
Read from file: 14 ms, sb length:6890
Read from file: 8 ms, sb length:6890
Read from file: 18 ms, sb length:6890
Read from file: 11 ms, sb length:6890
Read from file: 11 ms, sb length:6890
Read from file: 12 ms, sb length:6890
Read from file: 7 ms, sb length:6890
Read from file: 6 ms, sb length:6890
Read from file: 2 ms, sb length:6890
Read from file avg:10.625 ms


You may have noticed that the RPI has a slow start and consistent after few iterations while the PC results are varying. In one occurrence, the PC "write" scenario is higher than most of RPI results. On average, the PC "write" scenario is ONLY 1.36 times faster than the RPI. That is really impressive for the RPI. For the "read" scenario, the PC is 4.7 times faster. Finally, by adding the cost on the table, the Raspberry Pi offers a way better cost-performance ratio. By extrapolating these results, it is not a surprise to see new/old companies building computers with several low cost processors such as ARM.

Sunday, January 13, 2013

Groove your Raspberry Pi

After playing with the GPIO by using Python as a programming language with my nephews, I was tempted to augment the Raspberry Pi (RPI) with Groovy programming language. Just image what you can do with a small machine and a modern programming language. To do that, you need to install Java and Groovy. Here I provide straightforward instructions to quickly groove your RPI.

Get a new 4GB+ SD card and flash the "Soft-float Debian, wheezy" image. The image is available at http://www.raspberrypi.org/downloads

Since you need more space to install Java and Groovy, you need to resize a partition or create a new partition. Here I provide instructions to resize the root file system for simplification. To resize the root file system, use raspi-config tool and select expand_rootfs; it will use all available space for that partition. Then reboot your RPI.

After run df -h to verify if the root file system has been resized.

Get Java 7 soft floating-point for embedded Linux (ARMv6/7 Linux - Headless EABI, VFP, SoftFP ABI, Little Endian) http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html

Create a java directory where you will unpack Java:
mkdir /home/pi/java
cd /home/pi/java
tar -zxvf ejre-7u10-fcs-b18-linux-arm-vfp-client_headless-28_nov_2012.tar.gz

Verify that java is properly installed by doing
./ejre1.7.0_10/bin/java -version

Get Groovy at http://groovy.codehaus.org/Download, here I use version 1.8.8 but you can use the latest.

Create a groovy directory where you will unpack Groovy:
mkdir /home/pi/groovy
cd /home/pi/groovy
unzip groovy-binary-1.8.8.zip

Set Java and Groovy home environment variables add their bin directory to the PATH environment variable.
export JAVA_HOME=/home/pi/java/ejre1.7.0_10
export GROOVY_HOME=/home/pi/groovy/groovy-1.8.8
export PATH=$PATH:$JAVA_HOME/bin:$GROOVY_HOME/bin

Verify Groovy installation by doing
groovy -v
groovy -e "println 'Hello World'"

Voilà you have grooved your Rapsberry Pi!