Skip to content

Instantly share code, notes, and snippets.

@leikind
Created Oct 11, 2010
Embed
What would you like to do?
Myself versus consultants #1
real_time1 = Benchmark.measure { # Written by consultants
# Perform a query for every zone getting companies in that zone,
# initialize all active records, merge results into one list, remove duplicates
@advertisers = @zones.map{ |z| z.companies.available }.flatten.uniq
}.real
real_time2 = Benchmark.measure { # Written by me
@_advertisers = Company.available.find(:all, :include => :zones, :conditions => ['zones.id in (?)', @zones])
}.real
puts real_time1 # => 1.1079478263855
puts real_time2 # => 0.0442988872528076
puts (real_time1 / real_time2).to_s + ' times faster' # => 25.0107371786247 times faster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment