Created
June 9, 2021 22:14
-
-
Save grillermo/c89ab9bf717a050915bfb726195d7034 to your computer and use it in GitHub Desktop.
Ruby code benchmarking template using benchmark gem
This file contains 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
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