mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
a2ef9778ce
commit
fbd86c2017
1 changed files with 22 additions and 0 deletions
22
actionpack/lib/action_view/helpers/benchmark_helper.rb
Normal file
22
actionpack/lib/action_view/helpers/benchmark_helper.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue