Skip to content

Instantly share code, notes, and snippets.

@dblock
Created February 18, 2013 22:10
Show Gist options
  • 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
@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