AR dynamic finders are soooo slow..NOT
Published almost 6 years ago
Really ?
require 'benchmark' Benchmark.bm do |x| n = 10000 x.report do n.times do # "shit" exists Item.find_all_by_name "shit" Item.find_by_name "shit" # "fud" does not exist Item.find_all_by_name "fud" Item.find_by_name "fud" end end x.report do n.times do Item.find :all, :conditions => ["name = ?", "shit"] Item.find :first, :conditions => ["name = ?", "shit"] Item.find :all, :conditions => ["name = ?", "fud"] Item.find :first, :conditions => ["name = ?", "fud"] end end end # $ script/runner benchmark.rb # user system total real # 28.510000 1.270000 29.780000 ( 36.924108) # 26.100000 1.230000 27.330000 ( 34.318721)
So think again before you blame AR dynamic finders. Difference of 2 seconds for 40,000 queries shouldn’t really make anything slower.