The Linux system uses time to calculate when the command executes
When testing a program or comparing different algorithms, the execution time is very important, and a good algorithm should be the shortest. All UNIX-like systems are included time命令
, using this command to count time consumption. For example:
[[Email protected] ~]# time lsanaconda-ks.cfg install.log install.log.syslog satools textreal 0m0.009suser 0m0.002ssys 0m0.007s
The output information shows the real time ,user Time , and sys time spent by this command, respectively.
real时间
Is the time of the wall clock, that is, when the command begins execution to the end. This short time includes the time slices that other processes occupy, and the time it takes to block the process.
user时间
Refers to the CPU time that the process spends in user mode, which is the only time that is really spent executing the process, and the time in other processes and spent blocking states is not counted.
sys时间
Is the amount of CPU time spent in kernel mode, which represents the time it takes to take a system call in the kernel, which is the CPU time actually used by the process.
Shell Built-in also has a time command, when run time is called the system built-in command, should be built within the system has limited functionality, so it takes a while other functions need to execute binary files using the temporal command /usr/bin/time
.
Use to -o选项
write the execution time to a file:
/usr/bin/time-o Outfile.txt ls
To use the -a选项
append information:
/USR/BIN/TIME-A-o outfile.txt ls
Use the -f选项
format time output:
/usr/bin/time-f "time:%u" ls
Parameters after the-F option:
parameters |
description |
Td>%e
Real time, displayed in the format [hours:] minutes: Seconds |
% U |
user time. |
% S |
sys time. |
% C |
the command name and command-line arguments for timing. |
% D |
process Non-shared data region, in kilobytes. The |
%x |
command exits the status. The number of signals received by the |
% k |
process. |
% W |
The number of times that the process was swapped out of main memory. |
% Z |
The page size of the system, which is a system constant without the constant values in the system. The |
% P |
Process acquires a CPU time that is equal to User+system time divided by the total elapsed time. The average total memory usage (data+stack+text) of the |
% K |
process, in kilobytes. |
%w |
The number of times that the process actively makes a context switch, such as waiting for I/O operations to complete. |
% c |
the number of times the process was forced to make a context switch (due to time slice expiration). |