Quite a few Single Board Computers have made it to market and are gaining popularity with makers everywhere. Two of the biggest players in this space are the Raspberry Pi and the Beaglebone Black. Both advertise their various advantages, with the Raspberry Pi focusing on ease and educational use and the Beaglebone offering more centralized flexibility at the price of a higher learning curve. That being said, both SBCs are amazing pieces of hardware!
I thought that it might be a neat experiment to do a basic comparison of the Raspberry Pi versus the Beaglebone Black by looking at CPU performance while running a simple script. You may have seen my previous post on monitoring the computer performance – I simply ran this script for a little bit before starting my “stress test” script so that I could see average CPU usage before, during, and after the stress test.
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()
I ran this experiment on a Rasberry Pi B+ running Rasbian and an element14 Beaglebone Black running Debian. 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 two screenshots show the Pi and BBB’s CPU usage while no script is running.
You can see the Raspberry Pi was using 19% while the Beaglebone Black was using 25% of its CPU power.
Next I looked at running the test script without the division.
So the Pi’s CPU percent went from 19% to 64%. The Beaglebone Black jumped from 25% to 35%. It’s also interesting to note the raggedness of the Beaglebone’s usage versus the smoothness of the Pi’s. Not sure if this has something to do with psutil, but I feel like further investigation might provide an interesting reason for the difference.
Then I added division.
Here the Pi’s average percentage barely budged – only changing by 0.13%. The Beaglebone Black, however, made a 7% leap from 35% to 42%. This higher percentage is still lower than the Pi’s though.
So for a brief recap in case you didn’t want to read all of that:
|Raspberry Pi B+||Beaglebone Black|
|Basic CPU Usage (Avg %)|
|CPU Usage During Script Run (Avg %)|
|CPU Usage During Script Run w/Division (Avg %)|
I thought it was pretty interesting that the Pi used a smaller percentage initially but took a lot more CPU % to run the script. The difference between dividing and not was also surprising since it seemed to barely effect the Pi compared to the BBB.
This little test barely scratched the surface of what you can discover on the Pi and BBB by running different types of scripts and paying attention to different parameters that psutil returns. Initial State also makes it really easy to see what happened and get quick analysis on your results. So go experiment some more and let me know what you find!