Ruby on Rails的方法基准性能 [英] Ruby on Rails' Method Benchmark Performance

查看:65
本文介绍了Ruby on Rails的方法基准性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道几种rails方法的基准会是什么样子.任何人都可以运行自定义方法的网站吗?:

I wonder what the benchmark for few rails methods would look like. Anyone got a website that can run custom methods?:

User.count
#=> 1000000 (Let's say about that)

u = User.where(account_id: 5)
u.count
#=> 100000

u.map |a| a.account_id = 6 end

有没有办法测试这种基准?该迭代有多慢或多快?

Is there a way to test this sort of benchmark? How slow or fast is that iteration?

推荐答案

您可以使用ruby

You can use ruby benchmark module for this kind of test

require 'benchmark'
Benchmark.bm do |x|
  x.report { User.count }
  x.report { u = User.where(account_id: 5); u.count }
  x.report { u = User.where(account_id: 5); u.map |a| a.account_id = 6 end }
end

这篇关于Ruby on Rails的方法基准性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆