Created
October 11, 2010 14:26
-
-
Save leikind/620590 to your computer and use it in GitHub Desktop.
Myself versus consultants #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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