Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
Created September 1, 2011 23:40
Show Gist options
  • Select an option

  • Save RyanScottLewis/1187586 to your computer and use it in GitHub Desktop.

Select an option

Save RyanScottLewis/1187586 to your computer and use it in GitHub Desktop.
Benchmarking require calls..
  1. Modify the boot.rb file in your Rails application to reflect the one above.
  2. Run rails s
  3. Select all of the lines that include the following format: (000000.0) foobar required
  4. Copy those lines, open TextMate and paste into a /new/ document.
  5. Press F5 then press 1 to sort all lines in the document.

You can now tell which libraries/files take the longest to load.

require 'benchmark'
module Kernel
alias nonbenchmarked_require require
def require(file)
puts Benchmark.measure("#{file} required") {
nonbenchmarked_require(file)
}.format("%r %n")
end
end
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment