[FW] The Linux system uses time to calculate when the command executes

Source: Internet
Author: User

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:

Td>%e
parameters description
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).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.