Skip to content

Instantly share code, notes, and snippets.

@thegrubbsian
Created November 30, 2011 21:04
Show Gist options
  • Save thegrubbsian/1410814 to your computer and use it in GitHub Desktop.
Save thegrubbsian/1410814 to your computer and use it in GitHub Desktop.
Require Benchmark
require 'benchmark'
module Kernel
alias old_require require
def require(path)
output = nil
@required_files ||= []
benchmark = Benchmark.measure do
output = old_require path
end
@required_files << [path, benchmark]
puts path
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