Created
November 17, 2016 16:27
-
-
Save jgaskins/6de33a93c2077c1f691295c97d672c5d to your computer and use it in GitHub Desktop.
See how long it takes to load each dependency
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
# These don't load properly with this technique, so we preload them if the app | |
# needs them. :-( | |
require 'psych' | |
require 'bigdecimal' | |
alias zomg_require require | |
auto_create_hash = proc do |h,k| | |
hash = h[k] = {} | |
hash.default_proc = auto_create_hash | |
hash | |
end | |
$file_load_times = Hash.new(&auto_create_hash) | |
$current_file_hierarchy = [] | |
def require file | |
$current_file_hierarchy.push file | |
start = Time.now | |
result = zomg_require file | |
finish = Time.now | |
hash = $current_file_hierarchy.reduce($file_load_times) do |current, file| | |
current[file] | |
end | |
$current_file_hierarchy.pop | |
hash[file] = ((finish - start) * 1000).round(3) | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment