Linux命令——time
time命令常用于测量一个命令的运行时间,注意不是用来显示和修改系统时间的(这是date命令干的事情)。它能做的不仅仅是测量运行时间,还可以测量内存、I/O等的使用情况,说法是time a simple command or give resource usage,其中time一词我认为它应该是测量或测定的意思,并不单指时间。一个程序在运行时使用的系统资源通常包括CPU、Memory和I/O等,其中CPU资源的统计包括实际使用时间(real time)、用户态使用时间(the process spent in user mode)、内核态使用时间(the process spent in kernel mode)。但是简单的使用time命令并不能得到内存和I/O的统计数据。
time常用参数
time命令最常用的使用方式就是在其后面直接跟上命令和参数:
time [options]command [arguments...]
在命令执行完成之后就会打印出CPU的使用情况:
real 0m5.064s <== 实际使用时间(real time)
user 0m0.020s <== 用户态使用时间(the process spent in user mode)
sys 0m0.040s <== 内核态使用时间(the process spent in kernel mode)
time命令跟上-p参数可以只打印时间数值(秒数),不打印单位。
time [options]command [arguments...]
在命令执行完成之后就会打印出CPU的使用情况:
real 0m5.064s <== 实际使用时间(real time)
user 0m0.020s <== 用户态使用时间(the process spent in user mode)
sys 0m0.040s <== 内核态使用时间(the process spent in kernel mode)
time命令跟上-p参数可以只打印时间数值(秒数),不打印单位。