--Boundary-00B1oHIcIN0Lbu2c
Content-Type: text/plain;
  charsets-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

This little patch (against 1.8 branch) makes Benchmark#realtime a bit faster 
by directly evaluating elapsed real time instead of using Benchmark#measure.

The problem is Rails uses Benchmark#realtime a lot and it's not uncommon to 
see it called several thousand times during a single request. Existing 
function calls malloc 29 times and allocates at least 1.5K memory (that 
number can be more probably depending on the context where the block is 
defined, but I'm just guessing here). Patched function allocates 250b with 7 
mallocs.

In any case, once you repeat #realtime several thouthand times, you get a good 
chance of eating too much memory and triggering GC which slows down the whole 
thing (this and other cases are described in 
http://blog.pluron.com/2008/01/ruby-on-rails-i.html ).

--
Alex

--Boundary-00B1oHIcIN0Lbu2c
Content-Type: text/x-diff;
  charsets-ascii";
  nameenchmark_realtime.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filenameenchmark_realtime.patch"

Index: lib/benchmark.rb
--- lib/benchmark.rb	(revision 15364)
+++ lib/benchmark.rb	(working copy)
@@ -304,7 +304,10 @@
   # Returns the elapsed real time used to execute the given block.
   #
   def realtime(&blk) # :yield:
-    Benchmark::measure(&blk).real
+    r0  ime.now
+    yield
+    r1  ime.now
+    r1.to_f - r0.to_f
   end
 
 

--Boundary-00B1oHIcIN0Lbu2c--