Timing Linux Programs
Timing a Linux program helps one to understand how much time was spent.
The versatile Linuxtimecommand can be used for this.
Thetimecommand measures real (i.e.
wall clock time), user, and sys time.
The sys time is the time the program runs inside the kernel.
Knowing this, we can accurately measure how much effective CPU time was used (by combining them).
An example can be seen when timingsleep:
Here we timed thesleepcommand using thetimetool.
As a simple example, we could evaluate if any file system cache is operating on our system.
This time the result came back a little quicker, with 1.255 seconds saved on the command.
Likely a physical disk-based cache helped here.
Then, an alternative command can be used.
In Linux (or more specifically in Bash coding etc.
The command will obtain a process list and display the second column.
We use bothawkandsedto do so, and run each command 1000 times to see the difference in performance overall.
Wrapping up
In this article, we explored the Linuxtimecommand.
We clarified whatreal,userandsystimes indicate and how the latter two relate to CPU usage.
We also reviewed several examples of how to usetimein practical ways.
Can it be Fixed?.