bash - 使用时间命令进行基准测试

标签 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 中]

最佳答案

我认为它不适用于 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

希望对你有帮助, 亚历克斯。

关于bash - 使用时间命令进行基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7198356/

相关文章:

regex - 如何替换文件中的哈希字符?

python - 已结束的程序(Flask)一直将输出发送到 STDOUT?

c# - 如何在 C# 中处理带有持续时间的实际时间?

c++ - 快速排序 C++ 中的 Lambda

Java 内存基准测试

bash - 我如何检查用户是否存在于 bash 脚本中,如果提供的用户存在,我将如何重新询问新用户?

linux - 为什么我的 Linux 文本文件(使用 echo 创建)以换行符结尾?我怎样才能删除它?

python - 从数据中提取年份

ruby-on-rails - 我可以/应该如何处理 RoR 'datetime' "type"/"field"?

linux - 为什么 node.js+mongodb 不为每秒发送 100 个请求提供 100 个请求/秒的吞吐量?