测试进程运行时间的的各种-time

http://en.wikipedia.org/wiki/CPU_time

维基百科是个好东西。

CPU time:这个东西是真正的CPU time,CPU是分时的,每个进程都分到很多不连续的CPU时间片,时间片求和,即时CPU time(有点微积分的意思)。Top命令看的就是CPU time所占的百分比。(考虑到流水线的话,一个时间片内,不同的指令单元可能有一个指令(假如属于进程P1)读和另一个指令(假如属于指令P2)的执行么,这个时间片到底算谁的呢我也没搞清楚)

total CPU time:这个是在说多处理器并行处理的时候,各个CPU各个时间片的总和。

在linux下time命令会产生三个参数如下,在测试性能的时候经常会用到这个命令,由于系统调度的问题,即时是同一个程序,也可能得到不同的时间参数,所以测试同一个程序不同参数的情况下最好在同一个机器上,环境(测试的时候运行的进程,最好没有)也要相同。

real time:这个就是一个进程从开始到结束总共用的时间。包括I/O的时间和等待其他资源的时间。

user time:这个为进程在用户空间花费的时间。

sys time:这个为进程在kernel mode下处理花费的时间。一般进程通过系统调用进入内核空间。

一般而言,

CPU time = user time + sys time

real time = CPU time + I/O +其他等待时间(单核而言)

 

CPU time 和real time的关系:

“Elapsed real time is always same or more than CPU time for computer program which use only one CPU for processing. If no wait is involved for I/O or other resources, elapsed real time and CPU time are very similar.”

在多核的情况下CPU time(total CPU time) 和 real time 的关系:

"If a program uses parallel processing, total CPU time for that program would be more than its elapsed real time. (Total CPU time)/(Number of CPUs) would be same as elapsed real time if work load is evenly distributed on each CPU and no wait is involved for I/O or other resources."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值