top of page

Lab 6 - Algorithm Selection Lab

In this lab6 we will practice benchmarking and looking at different results produced by 3 different codes vol1.c vol2.c vol3.c which 3 of them are digital sounds.


We will test if all the algorithms produce the same output, how to measure them, how much time is taking and if there's any difference between them. For more detail information about this lab, you can check our wiki


This is the basic information of the 3 algorithms we are testing in this lab:

  1. The basic or Naive algorithm (vol1.c). This approach multiplies each sound sample by 0.75, casting from signed 16-bit integer to floating point and back again. Casting between integer and floating-point can be expensive operations.

  2. A lookup-based algorithm (vol2.c). This approach uses a pre-calculated table of all 65536 possible results, and looks up each sample in that table instead of multiplying.

  3. A fixed-point algorithm (vol3.c). This approach uses fixed-point math and bit shifting to perform the multiplication without using floating-point math.

Before starting with the testing we need to do some couple of steps:


Step 1: Find were the package is located

This package we can locate in one of our public file servers /public/spo600-algorithm-selection-lab.tgz

we can perform a copy command cp /public/spo600-algorithm-selection-lab.tgz . this way we can find it in our home directory.


Step 2: Unzip the file

After copying the file we can proceed to unzip using the following command

tar cvzf spo600-algorithm-selection-lab.tgz .


Step 3: Build the program

After it is unzipped we can change our directory where the Makefile is located and proceed to use the make command to build the program. This will create 3 output files that we, later on, can run.


Step 4: Run the program

To run the program is very easy, we just need to specify where the execution file is located an do the following on the command line: ./vol1 to check the vol1. We can change this to check the others files vol2 or vol3.


My Prediction:

I think vol1 will be the fastest and vol3 will be the slowest. I am guessing the results might be different depending on which architecture I will be using.


Build and Test:

Our instructor suggested we get the results in milliseconds so we had to add some code on the files to get this. I google how to get the milliseconds and encounter the code, including these two libraries #include <time.h> #include <unistd.h>



double time_spend = 0.0;
clock_t begin = clock();

clock_t end = clock();
time_spent += (double)(end-begin)/(CLOCKS_PER_SEC/1000);

printf("Time elapse is %f milliseconds\n", time_spent);

I use the following command to avoid typing the same thing and save me some time for ((x=0;x<3;x++)); do echo; echo ==== Trial $x; ./vol1; done;


With sample 500000000



With sample 600000000



With sample 800000000



Not all algorithms produce the same output as we can see on the different samples. I ran the samples 3 times and the results between each run are not that much the differences. But, what I notice is that the bigger the data the slower and more time consuming it gets, which kinda makes sense. The results between the server might be different each time since other students can be using the servers and this can affect the overall results.


The difference I found is that vol2 takes the longest following vol 1 and the fastest one being vol3. But, this might be different depending on which architecture server we working with. Overall we can conclude that vol3 is the fastest one.


For testing, I did open several bash terminal with the different servers and start running it at the same time. Maybe this can affect the results that we see on top.


For the memory usage of each program, I ran the command free -m to check it, these are the results:


Memory usage on Aarch64

AArchie



Bbetty



Ccharlie



Israel


Memory Usage on x86_64

Xerxes



Was my prediction accurate? At the beginning of the lab, I predicted vol1 to be the fastest and vol3 the slowest, which I was wrong. Vol3 resulted to be the fastest and Vol2 the slowest base on my tests. This might be how the algorithm is written, although 3 of them are doing the same thing their code has slightly different variations.


Personal Note:

This lab teaches me a lot about benchmarking which I used similar steps to do my project stage 1. Also, how from different architectures and servers the results might change a little bit. Or that having the same architecture your results can be different as well. Overall I enjoy doing this lab.

Recent Posts

See All

Lab 4 - 6502 Assembly Language String

For this lab, we had to pick 2 out of 4 options which will make us practice the ROM routines. Option 1 is a calculator, option 2 is getting data input, option 3 is hexdump and option 4 is a screen col

bottom of page