使用time命令进行基准测试

时间:2011-08-25 23:23:25

标签: bash time benchmarking

我正在尝试使用time命令作为一个简单的解决方案,用于对执行大量文本处理并进行大量网络调用的一些脚本进行基准测试。为了评估它是否合适,我尝试了:

/usr/bin/time -f "\n%E elapsed,\n%U user,\n%S system, \n %P CPU, \n%M
max-mem footprint in KB, \n%t avg-mem footprint in KB, \n%K Average total
(data+stack+text) memory,\n%F major page faults, \n%I file system
inputs by the process, \n%O file system outputs by the process, \n%r
socket messages received, \n%s socket messages sent, \n%x status"  yum
install nmap

得到了:

1:35.15 elapsed,
3.17 user,
0.40 system,
 3% CPU,
0 max-mem footprint in KB,
0 avg-mem footprint in KB,
0 Average total (data+stack+text) memory,
127 major page faults,
0 file system inputs by the process, 
0 file system outputs by the process,
0 socket messages received,
0 socket messages sent,
0 status

这不是我期望的 - 特别是0值。即使我将命令更改为ping google.com,套接字消息也是0.发生了什么?还有其他选择吗?

[我很困惑,如果它应该留在这里或发布在serverfault]

2 个答案:

答案 0 :(得分:1)

我认为它不适用于Linux;我假设你使用Linux,因为你说“strace”。手册页说:

Bugs

Not all resources are measured by all versions of Unix,
so some of the values might be reported as zero. The present
selection was mostly inspired by the data provided by 4.2 or
4.3BSD.

我在OSX系统(BSD-ish)上尝试“wget”来检查它是否报告套接字统计信息,并且至少有套接字工作:

0.00 user,
0.01 system, 
 1% CPU, 
0 max-mem footprint in KB, 
0 avg-mem footprint in KB, 
0 Average total (data+stack+text) memory,
0 major page faults, 
0 file system inputs by the process, 
0 file system outputs by the process, 
151 socket messages received, 
8 socket messages sent, 
0 status

希望有所帮助, 亚历克斯。

答案 1 :(得分:0)

请勿使用time进行基准测试。 time命令的某些字段按照[1]中的规定被破坏。但是时间(实际,用户和CPU时间)的基本功能仍然完好无损。

[1] Maximum resident set size does not make sense

相关问题