DEV Community

Qzhang125
Qzhang125

Posted on • Edited on

SPO600 Week 9 reflection

Hello, welcome to the week 9 of SPO600(Software Portability and Optimization) blog. In this week we will discuss the benchmarking and profiling.

Test a C program

This part we will do a very simple profiling test, we got 2 c-language programs:
The first is hello.c file

#include <stdio.h>

int main() {
        printf("Hello World!\n");
}
Enter fullscreen mode Exit fullscreen mode

The second is hello2.c file

#include <unistd.h>

int main() {
        write(1,"Hello World!\n",13);
}
Enter fullscreen mode Exit fullscreen mode

We could use a simple command

time make
Enter fullscreen mode Exit fullscreen mode

to retrieve how much time it is spending in each function or program.
Let's look at the result below:
Image description
As what we see above, the time has been divided up into 3 parts: real, user, and sys. The real time corresponds to the wall clock time, in this test it is 0.372 second. The user time is how much time this program is executing on my behalf, it is the time that the program is directly executing with my normal permissions, in this test it is 0.276 second. The system time(sys) is the amount of time that the kernel was doing stuff on behalf of this program, in this test it is 0.092 second. If we add the user time and system time together, the result should be very close to what we got for the real time of this test.

Fun things to know

Type command

less /proc/cpuinfo 
Enter fullscreen mode Exit fullscreen mode

Could display your cpu information.
Image description

Reflection

This week we worked on benchmarking and profiling. Benchmarking and profiling is super useful in real programming life. It provides a clear view to identify how much time that a program will consume, it helps programmers to pick up the best solution from tons of ideas.

Top comments (0)