基准测试控制器 +一次性多次一起查看
我正在学习如何对控制器/视图中的两个实现进行基准测试。他们在做同样的事情,但是一个是在视图中完成的,另一个是在控制器中完成的。代码如下所示。我的问题是:
- 是否可以测量同一操作一次性渲染 100 次所需的时间?
- 我当前的基准测试是否正确测量了视图+控制器时间的组合?
- 有没有更好的方法来做到这一点?
````
def sort_in_view
self.class.benchmark("$sort in view") do
@regions = Region.all
respond_to do |format|
format.html
end
end
end
def sort_in_controller
self.class.benchmark("$sort in controller") do
@regions = {}
Region.all.each do |r|
@regions[r] = r.countries.order_by_name
end
respond_to do |format|
format.html
end
end
end
I am learning how to benchmark two implementations in the controller/view. They are doing th e same thing, but one is done in view and another in controller. The code is shown below. My questions are:
- is it possible to measure the taken for the same action to render 100 times in one go?
- is my current benchmarking correctly measuring the combination of view + controller times?
- is there any better way to do this?
```
def sort_in_view
self.class.benchmark("$sort in view") do
@regions = Region.all
respond_to do |format|
format.html
end
end
end
def sort_in_controller
self.class.benchmark("$sort in controller") do
@regions = {}
Region.all.each do |r|
@regions[r] = r.countries.order_by_name
end
respond_to do |format|
format.html
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了多次运行每个案例以获得更准确的平均值,我最后使用了 Apache Benchmark。
这将运行该请求 100 次(并发度为 1),并为您提供平均值和百分位数的详细摘要。我针对本地计算机进行了基准测试,由于不需要浏览器渲染,因此可以节省时间。
In order to run each case many times to get a more accurate average, I used Apache Benchmark at the end.
This will run the request 100 times (with concurrency of 1), and give you a detailed summary of the mean and percentiles. I benchmark against my local machine, and it saves time since no browser rendering is required.
查看 benchmaek 结果,只需查看您的 Rails 日志
see benchmaek results,just see your Rails log