Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use mongoid-2.0.0.beta.19, add benchmark, upgrade README

  • Loading branch information...
commit 1af96c24e5d26ddd9bc54f218c034a1a3b89d688 1 parent 9a77298
@flyerhzm authored
View
23 Gemfile.lock
@@ -2,7 +2,7 @@ PATH
remote: .
specs:
mongoid-eager-loading (0.1.0)
- mongoid (~> 2.0.0.beta.18)
+ mongoid (~> 2.0.0.beta.19)
GEM
remote: http://rubygems.org/
@@ -16,16 +16,15 @@ GEM
bson_ext (1.1.1)
builder (2.1.2)
diff-lcs (1.1.2)
- i18n (0.4.1)
+ i18n (0.4.2)
mocha (0.9.9)
rake
- mongo (1.0.9)
- bson (>= 1.0.5)
- mongoid (2.0.0.beta.19)
- activemodel (~> 3.0)
- mongo (= 1.0.9)
- tzinfo (~> 0.3.22)
- will_paginate (~> 3.0.pre)
+ mongo (1.1.1)
+ bson (>= 1.1.1)
+ mongoid (2.0.0.alpha)
+ activemodel (>= 3.0.pre)
+ mongo (>= 0.19.1)
+ will_paginate (>= 3.0.pre)
rake (0.8.7)
rspec (2.0.1)
rspec-core (~> 2.0.1)
@@ -37,7 +36,6 @@ GEM
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
- tzinfo (0.3.23)
watchr (0.7)
will_paginate (3.0.pre2)
@@ -45,10 +43,11 @@ PLATFORMS
ruby
DEPENDENCIES
- bson_ext
+ bson_ext (~> 1.1.1)
bundler (>= 1.0.0)
mocha
- mongoid (~> 2.0.0.beta.18)
+ mongo (~> 1.1.1)
+ mongoid (~> 2.0.0.beta.19)
mongoid-eager-loading!
rspec (~> 2.0.0)
watchr
View
17 README.md
@@ -5,6 +5,8 @@ mongoid-eager-loading adds the eager loading feature for mongoid.
Originally it is my [pull request][0] for mongoid, but it is not accepted yet, so I created this gem to get the eager loading benefits easily for my projects.
+I only test it in mongoid-2.0.0.beta.19, maybe you can try it on other mongoid version, and let me know if it works fine.
+
Usage
-----
@@ -23,6 +25,20 @@ then you can use the eager loading like
Post.includes(:user)
Post.includes(:user, :comment)
+
+Benchmark
+---------
+
+I also ruun a [benchmark][1] on my local computer, the result is as follows
+
+ Starting benchmark...
+ user system total real
+ Finding 10 posts with person, without eager loading 0.010000 0.000000 0.010000 ( 0.006538)
+ Finding 10 posts with person, with eager loading 0.000000 0.000000 0.000000 ( 0.005235)
+ Finding 50 posts with person, without eager loading 0.020000 0.000000 0.020000 ( 0.027912)
+ Finding 50 posts with person, with eager loading 0.020000 0.000000 0.020000 ( 0.020103)
+ Finding 100 posts with person, without eager loading 0.040000 0.000000 0.040000 ( 0.055197)
+ Finding 100 posts with person, with eager loading 0.030000 0.010000 0.040000 ( 0.040644)
Author
------
@@ -33,3 +49,4 @@ Copyright
Copyright (c) 2010 Richard Huang. See LICENSE for details.
[0]: https://github.com/mongoid/mongoid/pull/391
+[1]: http://github.com/flyerhzm/mongoid-eager-loading/blob/master/benchmark/benchmark.rb
View
58 benchmark/benchmark.rb
@@ -0,0 +1,58 @@
+$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.db("mongoid_perf_test", :logger => Logger.new($stdout, :info))
+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
+ include Mongoid::EagerLoading
+ 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
+end
View
5 mongoid-eager-loading.gemspec
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "mongoid-eager-loading"
- s.add_dependency "mongoid", "~> 2.0.0.beta.18"
+ s.add_dependency "mongoid", "~> 2.0.0.beta.19"
s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rspec", "~> 2.0.0"
s.add_development_dependency "mocha"
s.add_development_dependency "watchr"
- s.add_development_dependency "bson_ext"
+ s.add_development_dependency "bson_ext", "~> 1.1.1"
+ s.add_development_dependency "mongo", "~> 1.1.1"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
Please sign in to comment.
Something went wrong with that request. Please try again.