Skip to content

Instantly share code, notes, and snippets.

@tomclose
Created October 23, 2015 07:59
Show Gist options
  • Save tomclose/f01a6fe09258d809ec6d to your computer and use it in GitHub Desktop.
Save tomclose/f01a6fe09258d809ec6d to your computer and use it in GitHub Desktop.

Simple timing

You can investigate how long something is taking using the Benchmark library.

require 'benchmark'

Benchmark.measure { some_code_I_want_to_profile }

Detailed profiling

For more detailed profiling (e.g. to tell you how much time is spent in which part of the call stack, use ruby-prof.

require 'ruby-prof'

result = RubyProf.profile { some_code_I_want_to_profile }

# To view the results you need to use a "Printer". For example, to view in a web browser:
File.open('results-stack.html', 'w') {|f| RubyProf::CallStackPrinter.new(result).print(f) }
File.open('results.html', 'w') {|f| RubyProf::GraphHtmlPrinter.new(result).print(f) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment