我创建了分析和存储数据的繁重脚本,我真的需要知道我的代码的哪些行大部分时间都在消耗。
Rubymine 是否具有分析器功能,或者可能以某种方式向其中添加分析器?
最佳答案
我也在寻找它,但没有成功。如果你发现了什么,请告诉我。
同时......在Ruby本身中有两个模块可以帮助你
基准 – http://apidock.com/ruby/Benchmark
你做这样的事情
require 'benchmark'
n = 50000
Benchmark.bm(7) do |x|
x.report("for:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
end
它会给你很好的分析结果表
user system total real
for: 1.050000 0.000000 1.050000 ( 0.503462)
times: 1.533333 0.016667 1.550000 ( 0.735473)
upto: 1.500000 0.016667 1.516667 ( 0.711239)
剖析器__ – http://apidock.com/ruby/Profiler__
使用这个模块最简单的方法就是
require 'profile'
在你的脚本完成后,它会爆出每个调用的数据。检查这个例子http://ruby.about.com/od/advancedruby/a/profile.htm
关于ruby-on-rails - rubymine 中的分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14917281/