Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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