<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Module: ActionView::Helpers::BenchmarkHelper</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Module</strong></td> <td class="class-name-in-header">ActionView::Helpers::BenchmarkHelper</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../../files/lib/action_view/helpers/benchmark_helper_rb.html"> lib/action_view/helpers/benchmark_helper.rb </a> <br /> </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> This helper offers a method to measure the execution time of a block in a template. </p> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000415">benchmark</a> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000415" class="method-detail"> <a name="M000415"></a> <div class="method-heading"> <a href="BenchmarkHelper.src/M000415.html" target="Code" class="method-signature" onclick="popupCode('BenchmarkHelper.src/M000415.html');return false;"> <span class="method-name">benchmark</span><span class="method-args">(message = "Benchmarking", options = {}) {|| ...}</span> </a> </div> <div class="method-description"> <p> Allows you to measure the execution time of a block in a template and records the result to the log. Wrap this block around expensive operations or possible bottlenecks to get a time reading for the operation. For example, let‘s say you thought your file processing method was taking too long; you could wrap it in a <a href="BenchmarkHelper.html#M000415">benchmark</a> block. </p> <pre> <% benchmark "Process data files" do %> <%= expensive_files_operation %> <% end %> </pre> <p> That would add something like "Process data files (345.2ms)" to the log, which you can then use to compare timings when optimizing your code. </p> <p> You may give an optional logger level as the :level option. (:debug, :info, :warn, :error); the default value is :info. </p> <pre> <% benchmark "Low-level files", :level => :debug do %> <%= lowlevel_files_operation %> <% end %> </pre> <p> Finally, you can pass true as the third argument to silence all log activity inside the block. This is great for boiling down a noisy block to just a single statement: </p> <pre> <% benchmark "Process data files", :level => :info, :silence => true do %> <%= expensive_and_chatty_files_operation %> <% end %> </pre> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>