Skip to content

Instantly share code, notes, and snippets.

@grillermo
Created June 9, 2021 22:14
Show Gist options
  • Save grillermo/c89ab9bf717a050915bfb726195d7034 to your computer and use it in GitHub Desktop.
Save grillermo/c89ab9bf717a050915bfb726195d7034 to your computer and use it in GitHub Desktop.
Ruby code benchmarking template using benchmark gem
require 'benchmark'
require 'launchy'
require 'ruby-prof'
reload!
def run
directory = Rails.root.join('tmp', 'profiles')
report_file = "#{directory}/benchmark.html"
FileUtils.mkdir_p directory
result = RubyProf.profile do
# YOUR CODE GOES HERE
end
printer = RubyProf::GraphHtmlPrinter.new(result)
File.open(report_file, 'w') { |file| printer.print(file) }
Launchy.open(File.join("file:///", File.expand_path(report_file)))
end
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment