gpt4 book ai didi

ruby - 分析 Sinatra 应用程序的最佳方式是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 06:38:06 24 4
gpt4 key购买 nike

我想弄清楚分析 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

关于ruby - 分析 Sinatra 应用程序的最佳方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4347466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com