aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/cache.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/benchmark.rb19
3 files changed, 17 insertions, 8 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 6fce65af4a..46081d11fb 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*2.3.0 [Edge]*
+* Add Benchmark.ms convenience method to benchmark realtime in milliseconds. [Jeremy Kemper]
+
* Updated included memcache-client to the 1.5.0.5 version which includes fixes from fiveruns and 37signals to deal with failover and timeouts #1535 [Joshua Sierles]
* Multibyte: add multibyte-safe Chars#ord rather than falling back to String#ord. #1483 [Jason Cheow]
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 10281d60eb..6a6c861458 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -143,13 +143,13 @@ module ActiveSupport
log("miss", key, options)
value = nil
- seconds = Benchmark.realtime { value = yield }
+ ms = Benchmark.ms { value = yield }
@logger_off = true
write(key, value, options)
@logger_off = false
- log("write (will save #{'%.2f' % (seconds * 1000)}ms)", key, nil)
+ log('write (will save %.2fms)' % ms, key, nil)
value
end
diff --git a/activesupport/lib/active_support/core_ext/benchmark.rb b/activesupport/lib/active_support/core_ext/benchmark.rb
index 79ba165e3a..ae57b152e8 100644
--- a/activesupport/lib/active_support/core_ext/benchmark.rb
+++ b/activesupport/lib/active_support/core_ext/benchmark.rb
@@ -1,12 +1,19 @@
require 'benchmark'
class << Benchmark
- remove_method :realtime
+ # Earlier Ruby had a slower implementation.
+ if RUBY_VERSION < '1.8.7'
+ remove_method :realtime
- def realtime
- r0 = Time.now
- yield
- r1 = Time.now
- r1.to_f - r0.to_f
+ def realtime
+ r0 = Time.now
+ yield
+ r1 = Time.now
+ r1.to_f - r0.to_f
+ end
+ end
+
+ def ms
+ 1000 * realtime { yield }
end
end