Created
August 31, 2011 11:27
-
-
Save mat/1183343 to your computer and use it in GitHub Desktop.
ruby-prof irb helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.irbrc | |
# $ gem install ruby-prof | |
# $ irb | |
# >> profile2file { 500_000.times{345345 ** 15} } | |
# Find profile results in /Users/mat/profile-1314789858.[txt|html] | |
# => 500000 | |
module Kernel | |
def profile2file(filename = "profile-#{Time.now.to_i}") | |
require 'ruby-prof' | |
block_result = nil | |
profile_result = ::RubyProf.profile do | |
block_result = yield | |
end | |
File.open("#{filename}.txt" , "w") { |file| ::RubyProf::FlatPrinter.new(profile_result).print(file) } | |
File.open("#{filename}.html", "w") { |file| ::RubyProf::GraphHtmlPrinter.new(profile_result).print(file) } | |
$stderr.puts("Find profile results in #{File.expand_path(filename)}.[txt|html]") | |
block_result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment