wiki‎ > ‎

performance


time needed to load libs in 'require


require 'benchmark'

$require_level = 0

module Kernel

  alias require_without_timing require


  def require(path)

    result = seconds = nil


    begin

      $require_level += 1

      seconds = Benchmark.realtime { result = require_without_timing(path) }

    ensure

      $require_level -= 1

    end


    puts "{'%.5f' % seconds} {' '*$require_level}{path}" if result

    result

  end

end


Comments