Skip to content

Instantly share code, notes, and snippets.

@leikind
Created October 11, 2010 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/620590 to your computer and use it in GitHub Desktop.
Save leikind/620590 to your computer and use it in GitHub Desktop.
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