如何快速对脚本进行基准测试
我看过很多博客,作者讨论如何组合快速基准测试,例如 Ruby 1.9.0 vs Python 2.5.1 Antonio Cangiano“在凌晨 3 点拼凑在一起”。
有没有一种简单的方法可以将脚本计时到毫秒,就像我不知道的那样?他可能使用 OS X 的内置函数或单个库吗? Python 有这方面的标准库吗?
如果你要选择阻力最小的路径并在凌晨 3 点把它组合起来,你会怎么做?
I've seen a lot of blogs where authors discuss throwing together quick benchmark tests, like this Ruby 1.9.0 v Python 2.5.1 that Antonio Cangiano "throws together at 3am."
Is there a simple way to time a script to the millisecond like that that I'm unaware of? Is he probably using built-in functions of OS X or individual libraries? Does Python have a standard lib for this?
How would you do this if you were just going to take the path of least resistance and throw it together at 3am?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看一下
timeit
模块。Take a look at the
timeit
module.如果您只是追求基准测试,并且不太担心启动时间,并且希望它独立于编程语言并且您使用的是 Unix,那么您可能会使用 unix
time
:If you're after mere benchmarking, and you're not too worried about start-up time, and you want it to be programming language independent and you're on Unix, you'd probably use unix
time
:我不知道如何在 Ruby 中执行此操作,但在 Python 中我会这样做 -
显然,这是一个“凌晨 3 点基准测试”。没有多余的装饰。
I don't know how to do this in Ruby, but in Python I do this -
Obviously, this is a "throw together at 3am benchmark." No frills.
Ruby 有一个 Benchmark 模块作为标准发行版的一部分。使用起来很简单。在 Stack Overflow 上快速搜索将会找到很多其使用示例我已经做到了。
Ruby has a Benchmark module as part of the standard distribution. It's simple to use. A quick search here on Stack Overflow will turn up a lot of samples of its use that I've done.
对于 ruby 基准测试,请尝试使用
Benchmark.realtime 执行 此操作
#你的代码,这个
最后
还尝试提供更详细的总系统时间等的测量
for ruby benchmarking try this
Benchmark.realtime do
#your code,this
end
also try measure which give more detail total system time etc