#Bash 的 time 命令
time [OPTION]... CMD [ARG]...
功能
报告程序执行所消耗的时间。
类型
Bash 内置命令(关键字)。
存在同名的可执行文件
/usr/bin/time,可以输入完整路径或\time执行该命令。
参数
OPTION选项:-p- 以 POSIX 格式打印时间
CMD- 要执行的命令ARG- 命令CMD的参数
#字段
| 字段 | 说明 |
|---|---|
real | 程序从启动到退出,实际经过的时间 |
user | 程序在用户态,占用 CPU 的时间 |
sys | 程序在内核态,占用 CPU 的时间 |
#示例
$ time my_sleep 2
real 0m2.000s
user 0m0.001s
sys 0m0.003s
- 命令实际执行了 2 秒,其中用户态 CPU 时间 0.001 秒,内核态 CPU 时间 0.003 秒,其余时间处于阻塞状态不占用 CPU
#相关命令
| 命令 | 说明 |
|---|---|
| times | 报告 shell 的总耗时 |
| time (GNU) | 报告程序执行所消耗的时间 |
#手册
time: time [-p] pipeline
Report time consumed by pipeline's execution.
Execute PIPELINE and print a summary of the real time, user CPU time,
and system CPU time spent executing PIPELINE when it terminates.
Options:
-p print the timing summary in the portable Posix format
The value of the TIMEFORMAT variable is used as the output format.
Exit Status:
The return status is the return status of PIPELINE.