DEV Community

Qiwen Yu
Qiwen Yu

Posted on

SPO600-Lab6, Project Stage 1: Algorithm Selection Lab

Introduction

This is the Algorithm Selection Lab.In this lab, the goal is to investigate the impact of different algorithms which produce the same effect. Based on benchmarking, three algorithms for adjusting the volume of PCM audio samples were tested. It is crucial to remember not to compare the relative performance across different machines, because various systems have different microarchitectures, memory configurations, peripheral implementations, and clock speeds, from mobile-class to server-class (e.g. Intel Atom vs. Xeon; AMD APU vs. Threadripper; ARM Cortex-A35 vs. Neoverse-V1).

However, do compare the relative performance of the various algorithms on the same machine.

Procedures

Digital sound is typically represented as two streams of signed 16-bit integer signal samples. To change the volume of sound, each sample can be scaled (multiplied) by a volume factor, in the range of 0.00 (silence) to 1.00 (full volume). On a mobile device, the amount of processing required to scale sound will affect battery life.

The given six programs are:

  • vol0.c is the basic or naive algorithm, which using casting between integer and floating points. Expensive.
  • vol1.c does the math using fixed-point calculations.
  • vol2.c pre-calculates all 65536 different results, and then looks up the answer for each input value.
  • vol3.c is a dummy program, negative control.
  • vol4.c uses Single Instruction, Multiple Data (SIMD) instructions accessed through inline assembley (assembly language code inserted into a C program). Only for Aarch64.
  • vol5.c uses SIMD instructions accessed through Complier Intrinsics. This program is also specific to AArch64.
  1. Get example programs using tar -xvzf spo600-volume-examples.tgz -C ~/Lab6/
  2. Change directory to where the Makefile stored. Using make to compile c-scripts.
  3. Define SAMPLES in the header file vol.h and the scale of volume was set to 50% in this header file.
  4. The memory used by these algorithm can be measured using free -m command in terminal.
  5. Simple measure of time using time command.
  6. Find a way to measure performance, using #include <sys/time.h>

Prediction

My prediction is that algorithms vol5 and vol4 are faster than others, vol2 is medium speed, while vol1 and vol0 are slowest, may vary depends on situations.

Test in Aarch64

Simple test

Simple test using time command:

time command

Questions.

The prediction can be found at the above.

Q: Measure performance

struct timbal start, stop;
float elapsed;

gettimeofday(&start, 0);

for (x=0; x< SAMPLES; x++){
  data[x] = scale_sample(data[x], 0.5);
}

gettimeofday(&stop, 0);

elapsed = (stop.tv_sec - start.tv_sec)*1000.0f
Enter fullscreen mode Exit fullscreen mode

The running time is roughly between start and stop.

Oldest comments (0)