Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mat
Created August 31, 2011 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat/1183343 to your computer and use it in GitHub Desktop.
Save mat/1183343 to your computer and use it in GitHub Desktop.
ruby-prof irb helper
# ~/.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