bundle_benchmark 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58e73135f655088d1ad1b69be2a38e7b969d86ec
4
+ data.tar.gz: 81bdb9ebfb7e840be897d0dcabd9eb21f29f3f0c
5
+ SHA512:
6
+ metadata.gz: e42ce47410c88436391dd511ee9a2b433611a13dc8e30c2e8ec9aa894c46bba0f34e3d964ada20d47b5eed2381d978076a771c235e33a12bdd9bd79394f9fe00
7
+ data.tar.gz: 4ce8e8414ee3648c76482ab309f211792fc1c872287099360a036149b83696e148602e7160665d97a3c6e033f02a472eddf0462ceb72d9de70423b146ed99f8c
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bundle_benchmark.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Kane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ # Bundle Benchmark
2
+
3
+ :gem: Because loading gems can take longer than you think
4
+
5
+ ```sh
6
+ bundle_benchmark
7
+ ............................................................[DONE]
8
+
9
+ Gem Time(sec) Pct %
10
+ --------------------------------------------------
11
+ rails 2.4161 26.9%
12
+ mongoid 0.9279 10.3%
13
+ fog 0.7707 8.6%
14
+ newrelic_rpm 0.5839 6.5%
15
+ geocoder 0.3578 4.0%
16
+ delayed_job 0.3162 3.5%
17
+ bitly 0.2703 3.0%
18
+ sass 0.2651 3.0%
19
+ tire 0.2592 2.9%
20
+ --------------------------------------------------
21
+ Total 4.8583 100.0%
22
+ ```
23
+
24
+ Forked from [this awesome gist](https://gist.github.com/panthomakos/2588879) by [Pan Thomakos](https://github.com/panthomakos)
25
+
26
+ ## Installation
27
+
28
+ ```sh
29
+ gem install bundle_benchmark
30
+ ```
31
+
32
+ No need to add it to your Gemfile.
33
+
34
+ ## Use It
35
+
36
+ In your project directory, run:
37
+
38
+ ```sh
39
+ bundle_benchmark
40
+ ```
41
+
42
+ To benchmark a specific Gemfile, run:
43
+
44
+ ```sh
45
+ BUNDLE_GEMFILE=~/Projects/project_n/Gemfile bundle_benchmark
46
+ ```
47
+
48
+ To only require certain groups - like Rails does - do
49
+
50
+ ```sh
51
+ # default rails development groups
52
+ BUNDLE_GROUPS=default,development,assets bundle_benchmark
53
+ ```
54
+
55
+ ## Now What?
56
+
57
+ Read this article
58
+
59
+ http://iain.nl/getting-the-most-out-of-bundler-groups
60
+
61
+ ## The Results
62
+
63
+ I was able to reduce gem load time from 12.1 seconds to 6.7 seconds - over 5 seconds!
64
+
65
+ Here’s what I did:
66
+
67
+ 1. Added :console group like the article above suggested
68
+
69
+ 1. Commented out `ruby-prof`, `oink`, and `debugger` when not in use
70
+
71
+ 1. Moved `newrelic_rpm` and `turbo-sprockets-rails3` to :staging, :production groups
72
+
73
+ 1. Removed unused gems
74
+
75
+ ## Bonus
76
+
77
+ ```sh
78
+ script/rails console # or server, etc
79
+ ```
80
+
81
+ is faster than
82
+
83
+ ```sh
84
+ bundle exec rails console
85
+ ```
86
+
87
+ Try it yourself
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "benchmark"
5
+
6
+ groups = ENV["BUNDLE_GROUPS"].to_s.split(",")
7
+
8
+ # taken from https://github.com/carlhuda/bundler/blob/v1.2.4/lib/bundler/runtime.rb
9
+
10
+ REGEXPS = [
11
+ /^no such file to load -- (.+)$/i,
12
+ /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
13
+ /^Missing API definition file in (.+)$/i,
14
+ /^cannot load such file -- (.+)$/i
15
+ ]
16
+
17
+ groups.map! { |g| g.to_sym }
18
+ groups = [:default] if groups.empty?
19
+
20
+ def pull(dep)
21
+ required_file = nil
22
+
23
+ begin
24
+ # Loop through all the specified autorequires for the
25
+ # dependency. If there are none, use the dependency's name
26
+ # as the autorequire.
27
+ Array(dep.autorequire || dep.name).each do |file|
28
+ required_file = file
29
+ Kernel.require file
30
+ end
31
+ rescue LoadError => e
32
+ if dep.autorequire.nil? && dep.name.include?("-")
33
+ begin
34
+ namespaced_file = dep.name.gsub("-", "/")
35
+ Kernel.require namespaced_file
36
+ rescue LoadError
37
+ REGEXPS.find { |r| r =~ e.message }
38
+ regex_name = $1
39
+ raise if dep.autorequire || (regex_name && regex_name.gsub("-", "/") != namespaced_file)
40
+ raise e if regex_name.nil?
41
+ end
42
+ else
43
+ REGEXPS.find { |r| r =~ e.message }
44
+ raise if dep.autorequire || $1 != required_file
45
+ end
46
+ end
47
+ end
48
+
49
+ # get list of gems
50
+
51
+ dependencies = Bundler.setup.dependencies
52
+
53
+ # include rails first if it exists
54
+
55
+ rails_included = dependencies.map(&:name).include?("rails")
56
+ if rails_included
57
+ rails_time =
58
+ Benchmark.realtime do
59
+ require "rails/all"
60
+
61
+ # If you would prefer gems to incur the cost of autoloading
62
+ # Rails frameworks, then comment out this next line.
63
+ case Rails::VERSION::MAJOR
64
+ when 3
65
+ ActiveSupport::Autoload.eager_autoload!
66
+ when 4
67
+ Rails::Railtie::Configuration.eager_load_namespaces.each do |namespace|
68
+ namespace.eager_load!
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ # time loads
75
+
76
+ gems = {}
77
+
78
+ $VERBOSE = nil
79
+ dependencies.each do |dep|
80
+ if ((dep.groups & groups).any? && dep.current_platform?)
81
+ gems[dep.name] = Benchmark.realtime{ pull(dep) }
82
+ putc "."
83
+ end
84
+ end
85
+ puts "[DONE]\n\n"
86
+
87
+ # set real rails gem load time
88
+
89
+ if rails_included
90
+ gems["rails"] = rails_time
91
+ end
92
+
93
+ # calculate total for percentages
94
+
95
+ total = gems.map{|gem, time| time }.inject(0.0){|x, sum| sum + x }
96
+
97
+ # output results
98
+
99
+ format = "%-30s %9.4f %8.1f%%"
100
+ line = "-"*50
101
+
102
+ puts "%s %36s %9s" % ["Gem", "Time(sec)", "Pct %"]
103
+ puts line
104
+ gems.sort_by{|gem, time| time }.reverse.each do |gem, time|
105
+ puts format % [gem, time, (time / total * 100)]
106
+ end
107
+ puts line
108
+ puts format % ["Total", total, 100]
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bundle_benchmark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bundle_benchmark"
8
+ spec.version = BundleBenchmark::VERSION
9
+ spec.authors = ["Andrew Kane"]
10
+ spec.email = ["andrew@chartkick.com"]
11
+ spec.description = %q{Because loading gems can take longer than you think}
12
+ spec.summary = %q{Because loading gems can take longer than you think}
13
+ spec.homepage = "https://github.com/ankane/bundle_benchmark"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1 @@
1
+ require "bundle_benchmark/version"
@@ -0,0 +1,3 @@
1
+ module BundleBenchmark
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundle_benchmark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Because loading gems can take longer than you think
42
+ email:
43
+ - andrew@chartkick.com
44
+ executables:
45
+ - bundle_benchmark
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/bundle_benchmark
55
+ - bundle_benchmark.gemspec
56
+ - lib/bundle_benchmark.rb
57
+ - lib/bundle_benchmark/version.rb
58
+ homepage: https://github.com/ankane/bundle_benchmark
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.0
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Because loading gems can take longer than you think
82
+ test_files: []