Created
November 7, 2012 22:08
-
-
Save pmenglund/4034820 to your computer and use it in GitHub Desktop.
show slow require:s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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