aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-07-05 19:33:25 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-07-05 19:33:25 +0000
commitc9901176be597d593791d05fa9b6601055aa0fc2 (patch)
treee93fc73ca52e8414b82f9bcf618ff8be0cbb1a63 /actionpack/lib/action_view
parent063956b93c47601e38e4b0ceb181d0ff57534b46 (diff)
downloadrails-c9901176be597d593791d05fa9b6601055aa0fc2.tar.gz
rails-c9901176be597d593791d05fa9b6601055aa0fc2.tar.bz2
rails-c9901176be597d593791d05fa9b6601055aa0fc2.zip
benchmark helper takes an optional log level, defaults to :info. Chose symbols log levels rather than Logger::FOO constants for simplicity. Added benchmark helper test suite.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/benchmark_helper.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/benchmark_helper.rb b/actionpack/lib/action_view/helpers/benchmark_helper.rb
index 6214289de5..1d53be51db 100644
--- a/actionpack/lib/action_view/helpers/benchmark_helper.rb
+++ b/actionpack/lib/action_view/helpers/benchmark_helper.rb
@@ -9,16 +9,16 @@ module ActionView
# <%= expensive_notes_operation %>
# <% end %>
#
- # Will add something like "Notes section (0.345234)" to the log.
- def benchmark(message = "Benchmarking", &block)
- return if @logger.nil?
-
- bm = Benchmark.measure do
- block.call
+ # Will add something like "Notes section (0.34523)" to the log.
+ #
+ # You may give an optional logger level as the second argument
+ # (:debug, :info, :warn, :error). The default is :info.
+ def benchmark(message = "Benchmarking", level = :info)
+ if @logger
+ real = Benchmark.realtime { yield }
+ @logger.send level, "#{message} (#{'%.5f' % real})"
end
-
- @logger.info("#{message} (#{sprintf("%.5f", bm.real)})")
end
end
end
-end \ No newline at end of file
+end