使用time命令进行基准测试

3

我尝试使用 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 上]


1
time命令只有在跟踪代码被编译到内核中时才能输出值。我甚至不知道是否有任何跟踪代码曾经为这些特定参数编写过... - Neil
2
尝试使用strace来计算套接字调用。 - Foo Bah
是的,我正在尝试使用 strace -c 命令... 试图找出如何将数据 grep 到我所需的抽象级别。 - Tathagata
2个回答

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.

我在一个类似BSD的OSX系统上尝试使用“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

希望这有所帮助, Alex。

0

不要使用time进行基准测试。如[1]所述,time命令的某些字段已经损坏。但是,时间的基本功能(实际时间、用户时间和CPU时间)仍然完好无损。

[1] 最大驻留集大小没有意义


有趣!谢谢分享 - 我已经不再懒惰地尝试使用时间命令来进行基准测试。 - Tathagata

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接