sexta-feira, 4 de março de 2016

The difference of the performance between BeagleBone Black and the PC

In this research, we’ll talk about performance of different algorithms in two different computer architectures.


We’ll be using a desktop x86_x64(Intel Core i7 3770k 4.2ghz) and a BeagleBone Black, ARM (Cortex A8, 1ghz).

Introduction



In some cases, computers have lower performance aiming saving energy and preventing overheat. Others are just caused by hardware limitation.

To verify those differences we will test the preformance by saving the time and clocks that are spend when processing the same algorithm in different computers and ploting some graphs using the results as a base.


In this case, we will use the Bubble, Quick and Shell sort algorithms. The vector size will start in 5000 and will increase by 5000 every time the function is called again. The maximum point we're aiming will be 500000.

This experiment is also to show the difference, in practice, of time_t and clock. Time is an absolute measure of time, it's based in the "0 hour of unix". It counts the amount of seconds that has been passed since 1 January 1970, 00h00min. Clock, by the other hand, is a measure of clock ticks from the processor. It can be converted to seconds when divided by CLOCKS_PER_SECOND. It's more acurrate to calculate process times. In a short explanation, Time_t takes ALL the time since the process begin, while clock just take the process time.

We used the codes that are saved into the repository below:


Just a brief explanation of each code:

     -run.sh: 
        The executable file for running an specific code with bubble, quick or shell sort. 
               $ ./run.sh  file*  integer**
                 * file that we wish to execute
                 ** 1 Bubble Sort, 2 Quick Sort, 3 Shell Sort


     -run_all_x86.sh:  

        The executable file for running all the codes into an x86 hardware.
               $ ./run_all_x86.sh 

     -run_arm.sh:  

        The executable file for running all the codes into an arm hardware.
               $ ./run_arm.sh

     -trabalho_time.cpp: 

        The c++ code that measure the time spent on one of the 3 Sorts 10 times, and calculates the average and the standard deviation.
     
     -trabalho_clock.cpp:
        The c++ code that measure the clocks spent on one of the 3 Sorts 10 times, and calculates the average and the standard deviation.

     -gnu_test.cpp:

         The c++ code that receives the files of the the same type of test (time or clock), they need to be write down in an ascending order (..._1 , ..._2 , ..._3), and organize those 3 into another .txt file, whose name will be the 4th argument.
               $ g++ gnu_test.cpp -o gnu
           $ ./gnu file_1, file_2 , file_3, newfilename 

           *The gnu_teste.cpp need to be in the same directory as the results files.

     -others:

        files we wish to execute to test.

Before Starting:

As we will use some arm codes, first we need to install an arm compiler.


Open the terminal on linux and type the following lines:


$ sudo apt-get install libc6-armel-cross

$ sudo apt-get install binutils-arm-linux-gnueabi
$ sudo apt-get install libncurses5-dev

$ sudo apt-get install gcc-arm-linux-gnueabihf

$ sudo apt-get install g++-arm-linux-gnueabihf


To test into the BeagleBone Black:

The files needed for this test are:
    - run.sh
    - run_arm.sh
    - trabalho_clock.cpp
    - trabalho_time.cpp

    - time_arm
    - clock_arm

Let's install the Debian SO to the BeagleBone. For this, you'll need a MicroSD card with, at least, 4GB of memory.

You can download the SO over this link.

When the download's finished, connect the MicroSD in the computer and open the terminal. Go to the diretory where the file was saved and unzip it.

$ unxz <filename>.img.xz

Find the list of devices connected to your PC using
$ df -h
The location is different in each computer, so you must be able to find based in the size and if it's mounted in "/media/...". The name sometimes is very strange but it kinda obeys a pattern (/dev/mmc1cb1p1, for example... MMC is from Memory Card).

Once you're sure about the device name, pay attention and take the lasts digits after the last character (this one included) from it (in our example mmc1cb1p1 we took off p1).
Type:
$sudo dd if=<filename>.img of=<devicelocation> (in our example it would be /dev/mmc1cb1)

WARNING: it WILL take some minutes (~20 / 30). When it's finished, simple unmout the device.
$umount <devicelocation> 

Remove the MicroSD and it's done. Now, you can plug the MicroSD into the Beaglebone. Keep "user button" pressed and plug the BBB into the USB. As soon as the leds start to blink, release the user button.


Connect the BeagleBone into your computer and open the Linux terminal.
Fist check if it is really connected into your computer:
$ ifconfig 

When the connection appears with the IP 192.168.7.2, then it's connected.



Type:

$ ssh debian@192.168.7.2

Now save the directory that contains the downloaded files into the BB.
scp -r "path" debian@192.168.7.2:/debian/home 


Go to the directory that they were saved.


Then type:

$ make all
$ chmod +x run.sh
$ chmod +x run_arm.sh
$ ./run_arm.sh

After every step is finished, all the results will be saved into a .txt on the "saidas" directory that was automatically created. 


To test into the PC:


The files needed for this test are:
    - run.sh
    - run_all_x86.sh
    - trabalho_clock.cpp
    - trabalho_time.cpp

    - time_x86
    - clock_x86


After downloading the codes from the repository, open the terminal from Linux and go to the directory that they were saved.

Then type:
$ make all
$ chmod +x run.sh
$ chmod +x run_all_x86.sh
$ ./run_all_x86.sh

After every step is finished, all the results will be saved into a .txt on the "saidas" directory that was automatically created.

Get the data and create a graph using Gnuplot:

  The file needed for this part:

    - gnu_test.cpp

First download the file above into the 'saidas' directory that was created before.


Open linux terminal em go to the 'saidas' directory, then type:

$ g++ gnu_test.cpp -o gnu
$ ./gnu file_1, file_2 , file_3, newfilename

For example: 


$./xxxxxxx time_x86_1, time_x86_2, time_x86_3, pc_time

After doing this for every kind of test, type in the terminal:

$ sudo apt-get install gnuplot


after the dowload is finished, type:


$ gnuplot 


gnuplot> set title ’titleName’

gnuplot> set  xlabel 'vector length'; set ylabel 'ordinateName'
gnuplot> set key box title ’Sorting Functions’


gnuplot>  plot 'newfilename.txt' using 1:2:3 with yerrorbars title 'Quick STD'

gnuplot>  rep 'newfilename.txt' using 1:2 with lines title 'Quick Sort'

gnuplot>  rep 'newfilename.txt' using 1:4:5 with yerrorbars title 'shell STD'

gnuplot>  rep 'newfilename.txt' using 1:4 with lines title 'Shell Sort'

gnuplot>  rep 'newfilename.txt' using 1:6:7 with yerrorbars title 'Bubble STD'

gnuplot>  rep 'newfilename.txt' using 1:6 with lines title 'Bubble Sort'

Following the example before:


$ gnuplot 

gnuplot> set title ’PC - Time’

gnuplot> set  xlabel 'vector length'; set ylabel 'Time'
gnuplot> set key box title ’Sorting Functions’


gnuplot>  plot 'pc_time.txt' using 1:2:3 with yerrorbars title 'Quick STD'

gnuplot>  rep 'pc_time.txt' using 1:2 with lines title 'Quick Sort'

gnuplot>  rep 'pc_time.txt' using 1:4:5 with yerrorbars title 'Shell STD'

gnuplot>  rep 'pc_time.txt' using 1:4 with lines title 'Shell Sort'

gnuplot>  rep 'pc_time.txt' using 1:6:7 with yerrorbars title 'Bubble STD'

gnuplot>  rep 'pc_time.txt' using 1:6 with lines title 'Bubble Sort'
Then, click on the down arrow on the top left of the plot screen(on the left side of an green circular arrow), and select "Export to PDF" saving wherever you want. We will save into the 'saidas' directory. 
 
Results:


 - BeagleBone Black with Time:

 

  - BeagleBone Black with Clock:

 

 - PC with Time:


  
 - PC with Clock:
 

 

Conclusion:


After analysing the results, with the Shell and Quick Sort the performance difference does not appear much, but with the Bubble Sort it is very clear that the BeagleBone performance is very low compared to the PC. This can be verified by the difference in the growing rate.