<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,5 +6,7 @@ nbproject
 *.bundle
 *.o
 ext/cbson/Makefile
+lib/mongo_ext/Makefile
+benchmark
 *~
 *#*</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -37,16 +37,37 @@ LARGE = {
                         'developers','focus','building','mongodb','mongo'] * 20
 }
 
+require 'benchmark'
+
 def report(str, t)
   printf(&quot;%s%d\n&quot;, str.ljust(60, '.'), PER_TRIAL / t)
 end
 
+def profile(str)
+  if ENV['MONGO_PROFILE']
+    require 'rubygems'
+    require 'ruby-prof'
+    prof_results = RubyProf.profile do
+      yield
+    end
+    File.open(&quot;benchmark/#{str}.html&quot;, &quot;w&quot;) do |f|
+      RubyProf::GraphHtmlPrinter.new(prof_results).print(f, :min_percent =&gt; 5)
+    end
+  else
+    yield
+  end
+end
+
 def benchmark(str, proc, n, db, coll_name, object, setup=nil)
   coll = db.collection(coll_name)
   setup.call(coll, object) if setup
-  t0 = Time.new
-  n.times { |i| proc.call(coll, object, i) }
-  report(str, Time.new.to_f - t0.to_f)
+  profile(str) do
+    GC.start
+    tms = Benchmark.measure do
+      n.times { |i| proc.call(coll, object.is_a?(Hash) ? object.dup : object, i) }
+    end
+    report(str, tms.real)
+  end
 end
 
 host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'</diff>
      <filename>bin/standard_benchmark</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4e2781faf10b6130904fcccf075e0808e722fe5c</id>
    </parent>
  </parents>
  <author>
    <name>Sean Cribbs</name>
    <email>seancribbs@gmail.com</email>
  </author>
  <url>http://github.com/mongodb/mongo-ruby-driver/commit/c357e7711429f429632261efd67541620432f908</url>
  <id>c357e7711429f429632261efd67541620432f908</id>
  <committed-date>2009-10-19T08:04:18-07:00</committed-date>
  <authored-date>2009-10-16T10:38:13-07:00</authored-date>
  <message>Modify standard_benchmark to allow profiling.</message>
  <tree>83814308b96c5dfb08cdaa30e55214557a8f374e</tree>
  <committer>
    <name>Mike Dirolf</name>
    <email>mike@dirolf.com</email>
  </committer>
</commit>
