使用 time 命令进行基准测试

发布于 2024-12-01 17:49:46 字数 957 浏览 0 评论 0原文

我正在尝试使用 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。这是怎么回事?还有其他选择吗?

[我很困惑它是否应该留在这里或发布在服务器故障中]

I'm trying to use the time command as a simple solution for benchmarking some scripts that do a lot of text processing and makes a number of network calls. To evaluate if its a good fit, I tried doing:

/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

and got:

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

which is not exactly what I was expecting - specially the 0 values. Even when I change the command to say ping google.com, the socket messages are 0. What's going on? Is there any alternative?

[And I'm confused if it should stay here or be posted in serverfault]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡水深流 2024-12-08 17:49:46

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

希望有帮助,
亚历克斯.

I think it's not working with Linux; I assume you're using Linux since you said "strace". The manual page says:

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.

I tried "wget" on an OSX system (which is BSD-ish) to check if it report socket statistics, and there at least socket works:

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

Hope that helps,
Alex.

暮倦 2024-12-08 17:49:46

不要使用时间来进行基准测试。 time 命令的某些字段已损坏,如 [1] 中指定的那样。然而,时间的基本功能(实际时间、用户时间和CPU时间)仍然完好无损。

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

Do not use time to benchmark. Some of the fields of the time command is broken as specified in [1]. However the basic functionality of time (real , user and cpu time) are still intact.

[1] Maximum resident set size does not make sense

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文