Requires ruby-prof (sudo gem install ruby-prof) Takes a block and profiles the results of running the block 100 times. The resulting profile is written out to Merb.root/log/#{name}.html. min specifies the minimum percentage of the total time a method must take for it to be included in the result.
Example
__profile__("MyProfile", 5) do 30.times { rand(10)**rand(10) } puts "Profile run" end
Assuming that the total time taken for #puts calls was less than 5% of the total time to run, #puts won’t appear in the profilel report.
Source Code
# File merb/core_ext/kernel.rb, line 206 def __profile__(name, min=1) require 'ruby-prof' unless defined?(RubyProf) return_result = '' result = RubyProf.profile do 100.times{return_result = yield} end printer = RubyProf::GraphHtmlPrinter.new(result) path = File.join(Merb.root, 'log', "#{name}.html") File.open(path, 'w') do |file| printer.print(file, {:min_percent => min, :print_file => true}) end return_result end
<code/>and<pre/>for code samples.