Skip to content

Instantly share code, notes, and snippets.

@mig
Created June 3, 2014 20:21
Show Gist options
  • Save mig/34f5a5e5a83502469f55 to your computer and use it in GitHub Desktop.
Save mig/34f5a5e5a83502469f55 to your computer and use it in GitHub Desktop.
Benchmark initializer load time
# place in railties/lib/rails/initializable.rb
def run_initializers(group=:default, *args)
return if instance_variable_defined?(:@ran)
t0 = Time.now
initializers.tsort.each do |initializer|
t = Time.now
initializer.run(*args) if initializer.belongs_to?(group)
puts("%60s: %.3f sec" % [initializer.name, Time.now - t])
end
puts "%60s: %.3f sec" % ["for all", Time.now - t0]
@ran = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment