time和/usr/bin/time
當我在bash
中敲入time
命令時,運行的其實是bash
內置的time
命令:
$ time
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ type time
time is a shell keyword
這個time
命令有一個-p
選項,表示以posix
格式輸出:
$ time -p
real 0.00
user 0.00
sys 0.00
除此以外,還有一個time
命令。不過我當前的機器並沒有安裝這個程序:
$ which time
which: no time in (/home/xiaonan/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
安裝一下,對比bash
內置的time
命令:
$ sudo pacman -S time
$ type time
time is a shell keyword
$ which time
/usr/bin/time
單獨運行“/usr/bin/time -p
”,只會輸出命令的幫助選項:
$ /usr/bin/time -p
Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]
[--portability] [--format=format] [--output=file] [--version]
[--help] command [arg...]
需要加上具體的需要度量時間的命令:
$ /usr/bin/time -p echo
real 0.00
user 0.00
sys 0.00
此外也可以給出命令執行的詳細信息:
$ /usr/bin/time -v echo
Command being timed: "echo"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1536
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 70
Voluntary context switches: 1
Involuntary context switches: 1
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0