diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-09 11:17:11 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-12-09 11:17:11 -0800 |
commit | e8c4939fb3366472021c1af1331bfdfe5d7a5d75 (patch) | |
tree | 0f1d9e20cb5a0e30820f6ccc8e9dd735e3273f1f /activesupport/lib | |
parent | c3fe6ebbfaedff8d6dd8f590bdd237fac174faac (diff) | |
download | rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.tar.gz rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.tar.bz2 rails-e8c4939fb3366472021c1af1331bfdfe5d7a5d75.zip |
Benchmark.ms
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/benchmark.rb | 19 |
2 files changed, 15 insertions, 8 deletions
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 |