About a month ago I published a comparison between the Raspberry Pi B+ and Beaglebone Black. It wasn’t very long after that that Raspberry Pi caused quite a hubbub with the release of the Raspberry Pi 2. This new little guy boasts 4 cores and an ARMv7 processor.
It took a while to get my hands on one, but once I did I wanted to run the same performance test that I did on the B+ and Beaglebone Black. This basic comparison looks at CPU performance while running a simple script.
Instead of messing with the settings and background tasks of the computers, I decided to run the test in their basic boot environment (command line, not GUI) for a more “practical” comparison (since you’d actually be using this environment for your projects).
I used the same script from my tutorial on monitoring computer performance to see average CPU usage before, during, and after running the stress test script.
If you’d like to replicate my test, you’ll need to install psutil with
sudo pip install python-psutil
along with the Initial State streamer.
Turn on your device and make sure you have an internet connection.
Type this command into the command line:
\curl -sSL https://get.initialstate.com/python -o - | sudo bash
Follow the prompts – if you say “Y” to the “Create an example script?” prompt, then you can designate where you’d like the script and what you’d like to name it. Your Initial State username and password will also be requested so that it can autofill your Access Key. If you say “n” then a script won’t be created, but the streamer will be ready for use.
Either use your example script to get your Access Key or create one from scratch and start streaming!
## Import psutil (which we just installed) import psutil ## Import time for delays import time ## Import the ISStreamer module from ISStreamer.Streamer import Streamer ## Streamer constructor, this will create a bucket called Computer Performance ## you'll be able to see this name in your list of logs on initialstate.com ## your access_key is a secret and is specific to you, don't share it! streamer = Streamer(bucket_name="Pi Performance",access_key="[Your Access Key Here]",buffer_size=20) ## We will run this systems check 1000 times with 1 seconds between each loop ## so it will take a little less than 17 minutes to run sample_rate_in_ms=1000 for x in range(1000): streamer.log("sample", x) # Get total CPU usage cpu_percent = psutil.cpu_percent() streamer.log("cpu_total", cpu_percent) # Get individual CPU usage cpu_percents = psutil.cpu_percent(percpu=True) streamer.log_object(cpu_percents, key_prefix="cpu") # Get the virtual memory usage memory = psutil.virtual_memory() streamer.log_object(memory, key_prefix="virtual_mem") # Get the swap memory usage #swap = psutil.swap_memory() #streamer.log_object(swap, key_prefix="swap_mem") # Get the network usage network = psutil.net_io_counters() streamer.log_object(network, key_prefix="net_io") time.sleep(sample_rate_in_ms/1000) streamer.close()
My initial experiment was run on a Rasberry Pi B+ running Rasbian and an element14 Beaglebone Black running Debian. I then replicated it on a Raspberry Pi 2 running Rasbian. I tried to use various resources by having my test script ping Google, perform addition, stream to Initial State and append to an array in a tight loop. To make things even more interesting, I also ran a trial with floating point division added in.
## Import subprocess to make calls like in the terminal import subprocess ## Import the ISStreamer module from ISStreamer.Streamer import Streamer ## Streamer constructor, this will create a bucket called Computer Performance ## you'll be able to see this name in your list of logs on initialstate.com ## your access_key is a secret and is specific to you, don't share it! streamer = Streamer(bucket_name="Performance Test",access_key="[Your Access Key Here]",buffer_size=20) ## Initialize a number numforstr = 12345 ## Create an array array = [str(numforstr)]; ## Tight while loop b/c no sleep while True: ## Ping Google res = subprocess.call(["ping","-c","1","www.google.com"]) ## Add to our number numforstr = numforstr + 12345 ## Stream the current number streamer.log("Number",numforstr) ## Add to our array array.append(str(numforstr)) ## Stream the last object in the array streamer.log("Last Array Index",array[len(array)-1]) ## Uncomment to perform division # div = numforstr/12344
To analyze my data, I used Initial State’s signal statistics.
These first three screenshots show the Pi 2, Pi and BBB’s CPU usage while no script is running.
The Raspberry Pi 2 is so cool because, as you can see here, it has 4 CPU cores. And it’s only using 2.5% of it’s CPU power at boot. The B+ was using 19% while the Beaglebone Black was using 25%!
The Pi 2 core percent use was 2.97%, 2.44%, 2.32%, and 2.27%, respectively, which averages out to the CPU total value of 2.5%.
I also wanted to see how much of a difference there was in CPU usage between the GUI and boot environments. I found that running the GUI only used 0.25% more power!
Now for the stress test. Let’s run the test script without the division.
So the Pi 2’s CPU percent went from 2.5% to 12.62%, which is still lower than the B+’s resting boot environment CPU percentage. The Pi B+’s CPU percent jumped from 19% to 64%, while the Beaglebone Black only went from 25% to 35%.
I pointed it out in my previous post, but Beaglebone’s usage appears much more ragged than the Pis’. I’m still not sure why. The Pi 2’s usage only looks more ragged than the B+’s because it is showing a much smaller range (0-13 compared to 0-65).
Now let’s add some division.
Like with the B+ at 64.51%, the Pi 2’s average percentage stayed roughly the same at 12.46%. The Beaglebone Black, however, made a 7% leap from 34.83% to 41.67%. This higher percentage is still lower than the B+’s but more than 3x that of the Pi 2.
So for a brief recap in case you didn’t want to read all of that:
|Raspberry Pi 2||Raspberry Pi B+||Beaglebone Black|
|Basic CPU Usage (Avg %)|
|CPU Usage During Script Run (Avg %)|
|CPU Usage During Script Run w/Division (Avg %)|
Basically, the Pi 2 blew the other two away. And these numbers make perfect sense when you’re using the board itself. Navigating the GUI is so fast and fluid, and previously unusable websites work perfectly. The other big plus to having multiple cores is that threaded modules (like the Initial State Streamer) can actually run concurrently with other threads like they should.
This was a very basic test, but I felt like it was applicable to the sorts of programs you might be running for your single board computer projects. Psutil can give you a lot of information, so looking into factors other than CPU usage is also very interesting. Initial State also makes it really easy to see what happened and get quick analysis on your results.
If you decide to run some experiments of your own, be sure to let me know what you find!