Skip to content

Instantly share code, notes, and snippets.

@pmenglund
Created November 7, 2012 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmenglund/4034820 to your computer and use it in GitHub Desktop.
Save pmenglund/4034820 to your computer and use it in GitHub Desktop.
show slow require:s
module Kernel
alias_method :require_orig, :require
def require(name)
$indent ||= 0
t1 = Time.now.to_f
$indent += 2
puts "#{" " * $indent}> #{name}"
require_orig name
t2 = Time.now.to_f
if t2 - t1 > 0.1
time = "\e[0m\e[31m%5.5f\e[0m" % [t2-t1]
elsif t2 - t1 > 0.03
time = "\e[0m\e[33m%5.5f\e[0m" % [t2-t1]
else
time = "\e[0m\e[32m%5.5f\e[0m" % [t2-t1]
end
puts "#{" " * $indent}< #{time} #{name}"
$indent -= 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment