Linux analysis of execution time with time
Under Linux, the time command can be used to measure the performance duration for a command line program. This article shows this with updatedb program as an example.
Call
The time command is simply specified before the program to be executed when it is called:
[root@tpw ~]# time updatedb real 1m5.682s user 0m0.543s sys 0m2.823s [root@tpw ~]#
The updatedb program is a suitable example. It searches the "whole" file system for all files and writes the information into a small data base. With the help of this database, you can then use the locate command to search for files very quickly later on. This search is more quickly than a normal search with the find command. However, the result does not reflect the current state, but the state of the data base (last call of the updatedb command.
As updatedb searches the entire file system and thus very random I/O accesses occur, the CPU spends most of its time waiting for the I/O when executing updatedb.
Analysis
The single values have the following meaning:
- real: Elapsed real time - the whole actual execution time.
- user: Total number of CPU-seconds that the process spent in user mode - the time during which the CPU actually executes the program's (user) code
- sys: Total number of CPU-seconds that the process spent in kernel mode - the time during which the CPU is busy executing kernel code for the program.
The CPU spends the rest of its time either running other programs or waiting for I/O. This also shows a parallel executed vmstat (see also Linux Performance Measurements using vmstat:
[user@tpw ~]$ vmstat 1 10 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 3 1 3276 17544 109672 869900 0 0 62 180 812 1340 17 6 75 2 0 1 1 3276 17000 110144 869900 0 0 464 76 815 1594 17 5 0 78 0 2 1 3276 16556 110552 869892 0 0 408 20 670 1415 2 5 0 93 0 0 1 3276 15980 111060 869936 0 0 508 0 844 1775 9 6 0 85 0 1 1 3276 15408 111524 869944 0 0 464 0 717 1592 5 4 0 91 0 0 1 3276 15000 111904 869976 0 0 372 12 627 1461 2 5 0 93 0 0 1 3276 15700 112788 869956 0 0 876 40 960 2177 5 7 0 88 0 0 1 3276 14420 113968 870136 0 0 1180 28 850 2020 5 11 0 84 0 0 1 3276 14628 115560 868288 0 0 1600 0 1281 2602 3 17 0 80 0 0 1 3276 14744 116996 866704 0 0 1696 0 1426 2806 7 19 0 74 0 [user@tpw ~]$
|
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|


