Skip to content

Instantly share code, notes, and snippets.

@grosser
Forked from webmat/benchmark.rb
Created May 11, 2012 20:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save grosser/2662191 to your computer and use it in GitHub Desktop.
Benchmark Your Bundle
#!/usr/bin/env ruby
# Temporarily add this dir to your path
# export PATH=~/gists/bundle_benchmark:$PATH
# cd to any of your project and run the benchmark
# cd ~/my-project
# benchmark.rb
require 'benchmark'
require 'bundler'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
def pull(dep)
required_file = nil # Make sure var is still in scope in rescue block
begin
# Loop through all the specified autorequires for the
# dependency. If there are none, use the dependency's name
# as the autorequire.
Array(dep.autorequire || dep.name).each do |file|
required_file = file
Kernel.require file
end
rescue LoadError => e
if dep.autorequire.nil? && dep.name.include?('-')
namespaced_file = nil # Make sure var is still in scope in rescue block
begin
namespaced_file = dep.name.gsub('-', '/')
Kernel.require namespaced_file
rescue LoadError
REGEXPS.find { |r| r =~ e.message }
raise if dep.autorequire || $1.gsub('-', '/') != namespaced_file
end
else
REGEXPS.find { |r| r =~ e.message }
raise if dep.autorequire || $1 != required_file
end
end
end
$VERBOSE = nil
require 'active_support/all'
require 'active_record'
Benchmark.bm do |x|
Bundler.setup.dependencies.each do |dependency|
x.report(dependency.name[0..20].ljust(21)) do
begin
pull(dependency)
rescue TypeError, NameError
end
end
end
end
gem install pru
bundle exec ruby benchmark.rb > report
cat report | pru 'split(/\s+/)' 'reject{|a| a.size != 6 }.map{|a| [a[0], a[1]] }.sort_by(&:last).reverse.map{|a| "#{a[0].ljust(21)} -> #{a[1]}" }.join("\n")' | head -n20
haml -> 0.320000
prawn -> 0.270000
mail -> 0.240000
webrat -> 0.230000
newrelic_rpm -> 0.210000
bourne -> 0.190000
pry -> 0.180000
httpclient -> 0.150000
jira4r -> 0.140000
after_commit -> 0.130000
capistrano -> 0.120000
tmail -> 0.120000
activemerchant -> 0.110000
migration_tools -> 0.100000
vpim -> 0.080000
nokogiri -> 0.080000
airbrake -> 0.080000
property_sets -> 0.070000
@bogdan
Copy link

bogdan commented May 15, 2012

Add bundle exec before ruby benchmark.rb plz

@grosser
Copy link
Author

grosser commented May 15, 2012

Im using bundle-exec so I dont have to worry about these things :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment