加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 介绍Sinatra应用程序的最佳方式是什么?

发布时间:2020-12-16 20:05:31 所属栏目:百科 来源:网络整理
导读:我试图找出什么最好的方式来配置一个Sinatra应用程序.我想要一个解决方案,给我一个路径中所有方法的时间概况,包括渲染哈尔. 有人分析了Sinatra的应用程序吗?任何指针? 解决方法 这是一种有效的技术,不知道它是否是最好的. require 'sinatra'require 'profi
我试图找出什么最好的方式来配置一个Sinatra应用程序.我想要一个解决方案,给我一个路径中所有方法的时间概况,包括渲染哈尔.

有人分析了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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读