Permalink
Browse files

update benchmark for eager loading

  • Loading branch information...
1 parent 0c7b4f7 commit 81b708256df9c728a59cd9581d466bded91934e7 @flyerhzm committed Jan 20, 2011
Showing with 23 additions and 5 deletions.
  1. +23 −5 perf/eager_loading_benchmark.rb
@@ -4,7 +4,8 @@
require "mongoid"
Mongoid.configure do |config|
- config.master = Mongo::Connection.new.db("mongoid_perf_test", :logger => Logger.new($stdout, :info))
+ #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
@@ -31,26 +32,43 @@ class Post
end
puts "Starting benchmark..."
-Benchmark.bm do |bm|
+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
+
+# user system total real
+#Finding 10 posts with person, without eager loading 0.000000 0.000000 0.000000 ( 0.004790)
+#Finding 10 posts with person, with eager loading 0.010000 0.000000 0.010000 ( 0.002065)
+#Finding 50 posts with person, without eager loading 0.010000 0.000000 0.010000 ( 0.021131)
+#Finding 50 posts with person, with eager loading 0.010000 0.000000 0.010000 ( 0.007007)
+#Finding 100 posts with person, without eager loading 0.050000 0.010000 0.060000 ( 0.060699)
+#Finding 100 posts with person, with eager loading 0.010000 0.000000 0.010000 ( 0.014336)
+#Finding 1000 posts with person, without eager loading 0.470000 0.020000 0.490000 ( 0.549790)
+#Finding 1000 posts with person, with eager loading 0.170000 0.010000 0.180000 ( 0.184104)
+

0 comments on commit 81b7082

Please sign in to comment.