Skip to content

Instantly share code, notes, and snippets.

@dblock
Created February 18, 2013 22:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblock/4981231 to your computer and use it in GitHub Desktop.
Save dblock/4981231 to your computer and use it in GitHub Desktop.
Measure how long require(s) take.
if ENV['DEBUG_REQUIRE']
require 'benchmark'
def require(file)
@@first ||= Time.now
rc = false
ts = Benchmark.measure do
rc = super
end
if ENV['DEBUG_REQUIRE'].to_f < ts.total
total = ts.format("%t require #{file}")
from_start = (Time.now - @@first).to_i
$stdout.puts "#{total} (#{from_start} second(s) from start)"
end
rc
end
end
@dblock
Copy link
Author

dblock commented Feb 18, 2013

Add the following to config/boot.rb:

require File.expand_path('../initializers/debug_require', __FILE__)

@DaveCollinsJr
Copy link

Thanks for this! Very useful!!

@angelacode
Copy link

I am not using Rails....how would I enable this same solution? I don't use a framework since it's not a web-app, it's interacting with API's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment