rubymine中的探测器

时间:2013-02-17 02:04:41

标签: ruby-on-rails performance profiling rubymine

我创建了大量的脚本来分析和存储数据,我真的需要知道我的代码中哪些行消耗大部分时间。 Rubymine是否具有探查器功能,或者可能以某种方式添加探查器?

1 个答案:

答案 0 :(得分:2)

我也在寻找它,但没有成功。如果您发现了什么,请告诉我。

同时......在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)

Profiler __ - http://apidock.com/ruby/Profiler__

使用此模块的最简单方法是require 'profile',在脚本完成后,它会清除每次调用的数据。

请查看此示例http://ruby.about.com/od/advancedruby/a/profile.htm