diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 8c4888b0058..d0dae92dd24 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -439,6 +439,13 @@ def console(group = nil) require 'irb' IRB.start end + + desc "benchmark [GROUP]", "Displays the time taken for each each gem to be loaded into the environment" + def benchmark(group = nil) + Bundler.ui.debug! + Bundler.ui.debug "Gem require times as included by bundle:" + group ? Bundler.require(:default, *(group.split.map! {|g| g.to_sym })) : Bundler.require + end desc "version", "Prints the bundler's version information" def version diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 5761694a9ef..832b8c8479b 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -64,8 +64,10 @@ def require(*groups) # dependency. If there are none, use the dependency's name # as the autorequire. Array(dep.autorequire || dep.name).each do |file| + start = Time.now.to_f if Bundler.ui.debugging? required_file = file Kernel.require file + Bundler.ui.debug " * #{file} (#{((Time.now.to_f-start)*1000.0).round} ms)" if Bundler.ui.debugging? end rescue LoadError => e REGEXPS.find { |r| r =~ e.message } diff --git a/lib/bundler/ui.rb b/lib/bundler/ui.rb index c483216aaf7..620629190c8 100644 --- a/lib/bundler/ui.rb +++ b/lib/bundler/ui.rb @@ -16,6 +16,10 @@ def info(message) def confirm(message) end + + def debugging? + false + end class Shell < UI attr_writer :shell @@ -27,7 +31,11 @@ def initialize(shell) end def debug(msg) - @shell.say(msg) if @debug && !@quiet + @shell.say(msg) if debugging? + end + + def debugging? + @debug && !@quiet end def info(msg) diff --git a/spec/other/benchmark_spec.rb b/spec/other/benchmark_spec.rb new file mode 100644 index 00000000000..139f1a9b752 --- /dev/null +++ b/spec/other/benchmark_spec.rb @@ -0,0 +1,16 @@ +require "spec_helper" + +describe "bundle benchmark" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + end + + it "prints out the require times for each gem" do + bundle :benchmark + + out.should =~ / \* rails \(\d+ ms\)/ + end +end