Skip to content

Instantly share code, notes, and snippets.

@aberant
Created May 10, 2011 16:18
Show Gist options
  • Save aberant/964791 to your computer and use it in GitHub Desktop.
Save aberant/964791 to your computer and use it in GitHub Desktop.
find_all_by_id is faster then exceptions
Benchmark.bm(10) do |x|
x.report("find all") {(1..10000).each { User.find_all_by_id( [99999])}}
x.report("find rescue") {(1..10000).each {User.find([9999]) rescue [] }}
end
user system total real
find all 3.200000 0.350000 3.550000 ( 4.630230)
find rescue 4.820000 0.380000 5.200000 ( 6.329360)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment