Created
June 9, 2011 14:25
-
-
Save farleyknight/1016831 to your computer and use it in GitHub Desktop.
Benchmarking the Rails boot process
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
# Stolen from here: | |
# http://alexyoung.org/2009/07/03/rapid-rails-boot-up-time/ | |
require 'benchmark' | |
module Kernel | |
alias old_require require | |
def require(path) | |
#unless caller.find { |caller_line| caller_line.match /dependencies\.rb/ } | |
# return old_require(path) | |
#end | |
output = nil | |
@required_files ||= [] | |
benchmark = Benchmark.measure do | |
output = old_require path | |
end | |
@required_files << [path, benchmark] | |
puts path | |
caller.each do |caller_line| | |
puts "\t#{caller_line}" | |
end | |
puts "" | |
#puts "#{path}:" | |
#puts loading_benchmark | |
output | |
end | |
def print_require_benchmark_stats | |
puts "Printing benchmark stats:" | |
@required_files ||= [] | |
@required_files.sort! { |a, b| b[1].real <=> a[1].real } | |
@required_files.each do |path, benchmark| | |
puts path | |
puts benchmark | |
end | |
end | |
end | |
at_exit { print_require_benchmark_stats } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment