Skip to content

Instantly share code, notes, and snippets.

@solnic
Last active August 29, 2015 14:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solnic/ca04f7470b7f5d9c7c66 to your computer and use it in GitHub Desktop.
Save solnic/ca04f7470b7f5d9c7c66 to your computer and use it in GitHub Desktop.
A hack to measure how long it takes to require bundled gems in a rails app
REQUIRE_DATA = {}
BUNDLED_GEMS = `bundle show | grep "*" | awk '{print $2}'`.split("\n").sort
require 'bigdecimal'
def require(name)
start = Time.now
ret = super
stop = Time.now
total = BigDecimal(stop-start, 6)
REQUIRE_DATA[name] = total if BUNDLED_GEMS.include?(name)
ret
end
def require_summary!
require_info = REQUIRE_DATA.to_a.sort_by(&:last).reverse
File.open("requires.log", "w") do |f|
require_info.each do |gem, time|
f << "#{gem}|#{time}\n"
end
end
end
sass-rails|0.350504
rails-html-sanitizer|0.0841502
loofah|0.0807085
nokogiri|0.06919
slim|0.0590941
coffee-rails|0.0531291
coffee-script|0.0510261
execjs|0.0493581
arel|0.042798
validates_timeliness|0.0417477
timeliness|0.0228528
tzinfo|0.0221143
gretel|0.020622
concord|0.0199939
adamantium|0.0181447
axiom-types|0.0180199
erubis|0.0161383
coercible|0.0148004
rom-sql|0.0141706
rom-rails|0.0109552
warden|0.0062394
bcrypt|0.00602871
memoizable|0.00388941
i18n|0.00387294
inflecto|0.00230061
bootstrap-sass|0.00190944
jquery-rails|0.00149442
transproc|0.00140992
jquery-ui-rails|0.00140623
charlatan|0.0012355
temple|0.000799056
ref|0.000597096
hike|0.000403201
rspec-rails|0.000357722
rails|0.000013796
tilt|0.000012404
thread_safe|0.00001217
json|0.00001214
thor|0.000011942
neat|0.000011416
virtus|0.000011168
rom|0.000010758
sequel|0.000010697
sass|0.00001034
sprockets|0.000009684
descendants_tracker|0.00000799
bourbon|0.000007212
equalizer|0.000006448
bitters|0.000006435
ice_nine|0.000006426
refills|0.000005494
rack|0.00000447
# paste above hack at the top of your config/application.rb
# HERE GOES YOUR application.rb
# at the end:
require_summary!
# look at requires.log that was created
@solnic
Copy link
Author

solnic commented Feb 5, 2015

As pointed out - it would give much better results when you run it in an isolated script where you require individual gem once and append time to the log.

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