Linux time command parameters and usage details--linux Test command Execution times command

Source: Internet
Author: User
Tags posix

" command " Time-executes the command and timings

"Format" time [-p] command [arguments ...]

Description

Execute command line "command [arguments]", when the command line execution finishes printing in standard output, the time statistic results of executing the command line, the statistic result contains the following data:

1) Actual time: The elapsed time from the command line execution to the end of the run;

2) User CPU time: The user CPU time that the command executes, that is, the command executes the sum of time in the user state;

3) System CPU time: The system CPU time that the command executes to complete, that is, the command executes the sum of time in the kernel mentality.

Where user CPU time and system CPU time are the sum of CPU time, that is, the total amount of time the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often when executing a command, the system also handles other tasks.

Another problem to be aware of is that even though the same command is executed every time, the time spent is not the same, and the time spent is related to the operation of the system.

Example 1:

1. # Time Date
2. Sun Mar 22:45:34 GMT-8 2006
3.
4. Real 0m0.136s
5. User 0m0.010s
6. SYS 0m0.070s
7. #


In Example 1, execute the command "time Date" (see Line 1th). The system executes the command "date" first, and the 2nd behavior command "date" executes the result. The 第3-6 behavior executes the time statistic result of the command "date", where the 4th line "real" is the actual time, the 5th line "user" is the CPU time of the users, and the 6th line "SYS" is the system CPU time. The display format of the above three kinds of time is mmmnn[. Fff]s.

In Example 1, CPU time = User CPU time + system CPU time = 0m0.010s + 0m0.070s = 0m0.080s, actual time is greater than CPU time, indicating that there are other tasks running while the date command is running.

"Parameter description"

-P Prints the time statistic result in POSIX default time format in seconds. The detailed output format is shown in Example 2.

Example 2:

1. # time-p Date
2. WEd Mar 00:33:11 GMT-8 2006
3. Real 0.11
4. User 0.00
5. SYS 0.02
6. #

In Example 2, the command "Time Date" is also executed (see line 1th). The system executes the command "date" first, and the 2nd acts the result of the command. The 第3-5 behavior executes the time statistic result of the command "date". Note that the time format of this example differs from the time format in Example 1, with the time display format of NN.FF after using the-p parameter, which is in seconds.

"Description of related environment variables"

TimeFormat the time format of the custom output.

We can also use the environment variable TimeFormat to customize the output time format [1]. The format uses the same escape character as the function printf in standard C, and uses the following escape sequence to specify the time format for the output:

%[prec][l][rus]
Where the option Prec is the specified time precision, which is the number of digits after the decimal point, and the option L indicates the use of minute seconds (in the format: mmmnn[. fff]s) format; The last character represents the type of time, where R represents the actual time, U represents the user CPU time, and S represents the system CPU time, and their units are in seconds.

The time command defaults to the output of the timeformat=$ ' nrealt%3lrnusert%3lunsyst%3ls ' format.

The time format with the-p parameter output is the same as timeformat=$ ' real%2rnuser%2unsys%2s '.

Example 3:

1. # exPort timeformat=$ ' real%2rnuser%2unsys%2s '
2. # time Date
3. Wed Mar 00:52:03 GMT-8 2006
4. Real 0.04
5. User 0.00
6. SYS 0.01
7. #

Comparative Example 2 and Example 3 shows the results, it is easy to find example 3, although the parameter-P is not used, but the output of the results and Example 2 is identical.

Of course, we can also modify the time format for any of your own liking.

Example 4:

1. #Exporttimeformat=$ ' Nhello, thinkerabc!nreal time:%lrnuser CUP time:%lunsystem CPU time:%ls '
2. # time Date
3. Wed Mar 01:09:26 GMT-8 2006
4.
5. Hello, thinkerabc!
6. Real Time:0m0.016s
7. User CUP time:0m0.006s
8. System CPU time:0m0.008s
9. #

Example 4 of the 第4-8 line is our custom output format.

This paper introduces three methods of specifying the time format, that is, the default time format, the POSIX default time format using the parameter-p and the setting environment variable TimeFormat the custom time format, the Linux system uses the following order:

1. POSIX default time format for parameter-p;

2. Environment variable TimeFormat custom time format;

3. The default time format.

"Exit Status description"

If the command command is able to execute, the exit status of the cmdlet is returned, otherwise the following exit status value is returned:

127 Command not found

126 command found, but cannot execute

1-125 Miscellaneous Errors

Linux time command parameters and usage details--linux Test command Execution times command

Related Article

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.