aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-27 08:17:25 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-27 08:17:25 +0000
commitfbd86c201722ac319818dc339d12d9716e4d13d9 (patch)
treeaa4be00632f8810a1d4985fb7d4125430c6acb8e
parenta2ef9778ce4cb5db18fe6d07e29fa50575ce77f1 (diff)
downloadrails-fbd86c201722ac319818dc339d12d9716e4d13d9.tar.gz
rails-fbd86c201722ac319818dc339d12d9716e4d13d9.tar.bz2
rails-fbd86c201722ac319818dc339d12d9716e4d13d9.zip
Added BenchmarkHelper that can measure the execution time of a block in a template and reports the result to the log
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1240 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/lib/action_view/helpers/benchmark_helper.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/benchmark_helper.rb b/actionpack/lib/action_view/helpers/benchmark_helper.rb
new file mode 100644
index 0000000000..ee1f88be82
--- /dev/null
+++ b/actionpack/lib/action_view/helpers/benchmark_helper.rb
@@ -0,0 +1,22 @@
+require 'benchmark'
+
+module ActionView
+ module Helpers
+ module BenchmarkHelper
+ # Measures the execution time of a block in a template and reports the result to the log. Example:
+ #
+ # <% benchmark "Notes section" do %>
+ # <%= expensive_notes_operation %>
+ # <% end %>
+ #
+ # Will add something like "Notes section (0.345234)" to the log.
+ def benchmark(message = "Benchmarking", &block)
+ bm = Benchmark.measure do
+ block.call
+ end
+
+ @logger.info("#{message} (#{bm.real})")
+ end
+ end
+ end
+end \ No newline at end of file