2013-02-17 74 views
6

我创建了一个分析和存储数据的重脚本,我真的需要知道大部分时间我的代码中哪些行消耗了。 Rubymine是否具有配置文件功能,或者有可能以某种方式向它添加配置文件?ruby​​中的剖析器

回答

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