平均执行时间
有没有什么好的 GNU 方法来测量某些命令行程序的平均(最坏情况,最好情况)执行时间?我有图像过滤器,未指定数量的图片,使用 bash 中的 for 循环过滤它们。到目前为止,我正在使用时间,但我找不到获取一些统计数据的方法。
is there any nice GNU way how to measure average (worst case, best case) execution time of some command line program? I have image filter, unspecified amount of pictures, filtering them using for-loop in bash. So far I am using time, but I can't find a way how to get some statistics.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将时间输出发送到某个文件,然后“工作”该文件
You can send the output of time to some file, and then "work" that file
有一个有趣的 Perl 程序,名为 dumbbench,它本质上是
时间的包装器命令。它会多次运行您的程序,丢弃异常值,然后计算一些统计数据。
作者有几篇文章(此处 和此处)概述a)为什么基准测试很糟糕,b)你可以制作什么样的漂亮图表来让你的基准测试数据不那么糟糕。
There's an interesting Perl program called dumbbench that's essentially a wrapper around the
time
command. It runs your program a number of times, throws away outliers, then calculates some statistics.The author has a couple of articles (here and here) outlining a) why benchmarking sucks, and b) what kind of pretty graphs you can make to make your benchmarking numbers suck a little less.
您的
时间
走在正确的轨道上。我用它来执行小型代码执行分析。然后,我使用 python 通过读取
time
的输出来收集统计信息。为了提高准确性,我通常会尝试 10 - 1000 次,具体取决于每个过程需要多长时间。我不熟悉任何进行此类分析的预装 GNU 应用程序。
You're on the right track with
time
. It's what I use to preform small code execution analyses.I then use python to collect the statistics by reading the output of
time
. In order to increase accuracy, I typically do the trial 10 - 1000 times, depending on how long each process takes.I'm not familiar with any pre-installed GNU application that does this sort of analysis.
如果您发现 {1..100} 语法不适合您,那么您应该查看 seq 命令。
我使用
env time
来执行时间程序,而不是 shell 的内置命令,后者不采用时间程序采用的所有参数。时间程序还采用其他参数来改变其输出的格式,您可能希望使用它来使数据更容易被另一个程序处理。 -p (--portability) 参数使其以 POSIX 格式输出(就像 BASH 的内置时间一样),但使用 -f 选项您可以获得更多控制。man 1 次
了解更多信息。收集数据后,一个简单的 Perl 或 Python 脚本就可以轻松解析和分析您的计时数据。
If you find that the {1..100} syntax doesn't work for you then you should have a look at the seq command.
I used the
env time
to execute the time program rather than the shell's built in command, which does not take all of the arguments that the time program takes. The time program also takes other arguments to alter the format of it's output, which you will probably want to use to make the data easier to process by another program. The -p (--portability) argument makes it output in the POSIX format (like BASH's builtin time does), but using the -f option you can get more control.man 1 time
for more info.After you have gathered your data a simple perl or python script can easily parse and analyze your timing data.
您应该考虑是否对外部循环进行计时并除以重复次数,而不是单独对每个迭代进行计时。如果您担心丢弃高点和低点,只需再进行几次迭代即可将它们淹没。
您可以捕获变量中时间的输出:
并做一些假数学< /em>:
或者只使用
bc
:You should consider whether to time the outer loop and divide by the repetitions rather than timing each iteration separately. If you're worried about discarding the high and low, just do a few more iterations to drown them out.
You can capture the output from time in a variable:
and do some fake math:
Or just use
bc
: