Skip to content

Instantly share code, notes, and snippets.

@will
Last active June 30, 2018 01:05
Show Gist options
  • Save will/b0cccbe6a578103e31553eb2a7c947aa to your computer and use it in GitHub Desktop.
Save will/b0cccbe6a578103e31553eb2a7c947aa to your computer and use it in GitHub Desktop.
# Now
irb(main):020:0> Benchmark.measure { User.all.group_by { |u| u.org }; nil }
=> #<Benchmark::Tms:0x005609082d33b0 @label="", @real=3.7103141639381647, @cstime=0.0, @cutime=0.0, @stime=0.18999999999999995, @utime=1.5, @total=1.69>
# eager loading orgs
irb(main):022:0> Benchmark.measure { User.eager(:org).all.group_by { |u| u.org }; nil }
=> #<Benchmark::Tms:0x0056090a1ccfa0 @label="", @real=1.3611143808811903, @cstime=0.0, @cutime=0.0, @stime=0.040000000000000036, @utime=1.1799999999999997, @total=1.2199999999999998>
# eager loading orgs, not finding deleted users, and only getting needed columns
irb(main):024:0> Benchmark.measure { User.eager(org: proc{|ds| ds.select(:id, :name)}).where(deleted_at:nil).select(:email, :name, :id, :org_id).all.group_by { |u| u.org }; nil }
=> #<Benchmark::Tms:0x00560909dd9da8 @label="", @real=0.014749959111213684, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment