Ruby on Rails的方法基准性能



我想知道少数rails方法的基准测试会是什么样子。有人拥有可以运行自定义方法的网站吗?:

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

有没有一种方法可以测试这种基准?迭代的速度有多慢?

您可以使用ruby基准测试模块进行这种测试

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

最新更新