Sha256: 3c957979996b6bef2cd333d7af4b38bbb7ac97b38ceaa6d8855cf3c1d3034dac
Contents?: true
Size: 1.91 KB
Versions: 2
Compression:
Stored size: 1.91 KB
Contents
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) require "rubygems" require "benchmark" require "mongoid" require "mongoid-eager-loading" Mongoid.configure do |config| #config.master = Mongo::Connection.new('localhost', 27018, :logger => Logger.new($stdout)).db("mongoid_perf_test") config.master = Mongo::Connection.new.db("mongoid_perf_test") end Mongoid.master.collection("people").drop Mongoid.master.collection("posts").drop class Person include Mongoid::Document include Mongoid::Timestamps field :name references_many :posts end class Post include Mongoid::Document include Mongoid::Timestamps field :title referenced_in :person end 10000.times do |n| person = Person.create(:name => "Test_#{n}") person.posts.create(:title => "Test_#{2*n}") person.posts.create(:title => "Test_#{2*n+1}") end puts "Starting benchmark..." Benchmark.bm(60) do |bm| bm.report("Finding 10 posts with person, without eager loading") do Post.limit(10).each { |p| p.person.name } end bm.report("Finding 10 posts with person, with eager loading") do Post.limit(10).includes(:person).each { |p| p.person.name } end bm.report("Finding 50 posts with person, without eager loading") do Post.limit(50).each { |p| p.person.name } end bm.report("Finding 50 posts with person, with eager loading") do Post.limit(50).includes(:person).each { |p| p.person.name } end bm.report("Finding 100 posts with person, without eager loading") do Post.limit(100).each { |p| p.person.name } end bm.report("Finding 100 posts with person, with eager loading") do Post.limit(100).includes(:person).each { |p| p.person.name } end bm.report("Finding 1000 posts with person, without eager loading") do Post.limit(1000).each { |p| p.person.name } end bm.report("Finding 1000 posts with person, with eager loading") do Post.limit(1000).includes(:person).each { |p| p.person.name } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid-eager-loading-0.3.1 | benchmark/benchmark.rb |
mongoid-eager-loading-0.3.0 | benchmark/benchmark.rb |