Skip to content

Instantly share code, notes, and snippets.

@JustinLove
Created February 10, 2013 23:30
Show Gist options
  • Save JustinLove/4751510 to your computer and use it in GitHub Desktop.
Save JustinLove/4751510 to your computer and use it in GitHub Desktop.
Hack to see why your program is taking so long to load
require 'benchmark'
$require_depth = 0
module TimedRequire
LIMIT = 0.0
def require(path)
#puts " #{' '*$require_depth}>>#{path}"
begin
$require_depth += 1
t = 0.0
t = Benchmark.realtime {super}
rescue Exception
puts "!!!!!!! exception during #{path} !!!!!!!"
raise
ensure
$require_depth -= 1
if t > LIMIT
puts "#{'%1.3f'%t}#{' '*$require_depth}<<#{path}"
end
end
end
def load(path)
#puts " #{' '*$require_depth}>>#{path}"
begin
$require_depth += 1
t = 0.01
t = Benchmark.realtime {super}
rescue Exception
puts "!!!!!!! exception during #{path} !!!!!!!"
raise
ensure
$require_depth -= 1
if t > LIMIT
puts "#{'%1.3f'%t}#{' '*$require_depth}<<#{path}"
end
end
end
end
extend TimedRequire
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment