Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1159 from pascalh1011/master
Browse files Browse the repository at this point in the history
Bundler.setup benchmark
  • Loading branch information
Andre Arko committed May 11, 2011
2 parents 05e48e3 + ed74e44 commit 71a12fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/bundler/cli.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/bundler/runtime.rb
Expand Up @@ -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 }
Expand Down
10 changes: 9 additions & 1 deletion lib/bundler/ui.rb
Expand Up @@ -16,6 +16,10 @@ def info(message)

def confirm(message)
end

def debugging?
false
end

class Shell < UI
attr_writer :shell
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions 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

0 comments on commit 71a12fe

Please sign in to comment.