Nil*_*ect 14 ruby profiling sinatra
我试图找出分析Sinatra应用程序的最佳方式是什么.我想要一个解决方案,它会给我一个路径中所有方法的时间配置文件,包括haml的渲染.
有没有人介绍过Sinatra应用程序?有什么指针吗?
这是一种有效的技术,不确定它是否是最好的.
require 'sinatra'
require 'profiler'
get '/' do
Profiler__.start_profile
do_it_fast
do_it_slow
do_it_fast
Profiler__.stop_profile
Profiler__.print_profile(STDOUT)
"done"
end
def do_it_fast
1.upto(100){ Math.sqrt(rand) }
end
def do_it_slow
1.upto(100_000){ (Math.sqrt(rand)).ceil }
end
#=> In the console:
#=> % cumulative self self total
#=> time seconds seconds calls ms/call ms/call name
#=> 68.45 2.82 2.82 3 940.00 1373.33 Integer#upto
#=> 11.41 3.29 0.47 100200 0.00 0.00 Kernel.rand
#=> 10.92 3.74 0.45 100000 0.00 0.00 Float#ceil
#=> 9.22 4.12 0.38 100200 0.00 0.00 Math.sqrt
#=> 0.00 4.12 0.00 2 0.00 5.00 Object#do_it_fast
#=> 0.00 4.12 0.00 1 0.00 4110.00 Object#do_it_slow
#=> 0.00 4.12 0.00 1 0.00 4120.00 #toplevel
Run Code Online (Sandbox Code Playgroud)
IMO,在这种情况下,最好的工具是perftools.rb,它基于Google Perftools.它甚至可以生成这样的图表(太棒了!):http://perftools-rb.rubyforge.org/examples/sinatra.gif
作为perftools.rb的常规用户,我可以说它极大地帮助您找到应用中的瓶颈并比较不同的策略.
在github.com上搜索"perftools.rb"
| 归档时间: |
|
| 查看次数: |
2151 次 |
| 最近记录: |