Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added read performance script that brandon and I used to speed things…

… up. Here for historical purposes.
  • Loading branch information...
commit 3f12beff8230c372f34a2226cd14b78074ed0919 1 parent 5073f8e
@jnunemaker jnunemaker authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 performance/reads.rb
View
44 performance/reads.rb
@@ -0,0 +1,44 @@
+require 'perftools'
+require 'pp'
+require 'benchmark'
+require 'rubygems'
+
+# Script Brandon and I used to benchmark reads while improving performance.
+# Included here for historical purposes.
+
+$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'mongo_mapper'
+
+MongoMapper.database = 'testing'
+
+class Site
+ include MongoMapper::Document
+
+ key :title, String
+end
+Site.collection.remove
+
+site = Site.create(:title => 'Testing')
+
+times = 1_000
+
+driver_result = Benchmark.realtime {
+ times.times{ Site.collection.find_one('_id' => site.id) }
+}
+
+mm_result = Benchmark.realtime {
+ times.times{ Site.first('_id' => site.id) }
+}
+
+puts 'Collection#find_one', driver_result, 'Site.first', mm_result, 'Ratio', mm_result / driver_result
+
+# PerfTools::CpuProfiler.start('prof_client') do
+# times.times{ Site.collection.find_one('_id' => site.id) }
+# end
+
+# PerfTools::CpuProfiler.start('prof_reads') do
+# times.times{ Site.find(site.id) }
+# end
+
+# system('pprof.rb --gif --ignore=Collection#find_one prof_reads > prof_reads.gif')
+# system('open prof_reads.gif')
Please sign in to comment.
Something went wrong with that request. Please try again.