Created
January 4, 2023 18:12
-
-
Save alexch/93068ae21c9fe20b6958fe442cdb6eb7 to your computer and use it in GitHub Desktop.
quick and dirty monkey patch to see which `require`d files are taking a long time to load
This file contains 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
# quick and dirty monkey patch to see which `require`d files are taking a long time to load | |
# Usage: 'require "benchmarking_require"' in spec_helper.rb | |
require "benchmark" | |
module Kernel | |
def require_with_benchmark path | |
x = nil | |
m = Benchmark.measure do | |
x = require_without_benchmark path | |
end | |
@@times << [path, m.total] if m.total > 0.1 | |
x | |
end | |
at_exit do | |
@@times.sort_by! { |x| -x[1] } | |
@@times.each do |time| | |
puts "#{"%1.4f" % time[1]}\t#{time[0].gsub(/.*\/gems\//, "")}" | |
end | |
end | |
alias_method :require_without_benchmark, :require | |
alias_method :require, :require_with_benchmark | |
@@times = [] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment