public
Created

Measure how long require(s) take.

  • Download Gist
debug_require.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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

Add the following to config/boot.rb:

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

Thanks for this! Very useful!!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.