Created
February 17, 2012 12:01
-
-
Save scotttam/1852968 to your computer and use it in GitHub Desktop.
Instrument bundler for gem load performance
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
def require(*groups) | |
gem_load_times = {} | |
groups.map! { |g| g.to_sym } | |
groups = [:default] if groups.empty? | |
@definition.dependencies.each do |dep| | |
# Skip the dependency if it is not in any of the requested | |
# groups | |
next unless ((dep.groups & groups).any? && dep.current_platform?) | |
required_file = nil | |
begin | |
# Loop through all the specified autorequires for the | |
# dependency. If there are none, use the dependency's name | |
# as the autorequire. | |
start_dep_time = Time.now | |
Array(dep.autorequire || dep.name).each do |file| | |
required_file = file | |
Kernel.require file | |
end | |
rescue LoadError => e | |
REGEXPS.find { |r| r =~ e.message } | |
raise if dep.autorequire || $1 != required_file | |
ensure | |
gem_load_times[dep.name] = Time.now - start_dep_time | |
end | |
end | |
puts "PRINTING OUT GEM LOAD TIMES" | |
sorted = gem_load_times.sort_by { |name, duration| duration} | |
total_time = 0.0 | |
sorted.each { |gem, duration| puts sprintf("%-25s | %5.3f", gem, duration); total_time += duration } | |
puts "--------------------------------------" | |
puts "Total Gem load time | #{total_time}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment