Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Created December 14, 2016 06:15
Show Gist options
  • Save fadhlirahim/8235b245522acdaf734ead321df02c1d to your computer and use it in GitHub Desktop.
Save fadhlirahim/8235b245522acdaf734ead321df02c1d to your computer and use it in GitHub Desktop.
Module.get_const vs Object.get_const vs Rails constantize
# run this in rails console
require 'benchmark/ips'
def track
track ||= Track.first
end
Benchmark.ips do |x|
x.report("Module.get_const") { Module.const_get("#{V1}::TrackPresenter").new(track) }
x.report("Object.get_const") {
Object.const_get("#{V1}::TrackPresenter").new(track)
}
x.report("constantize") { "#{V1}::TrackPresenter".constantize.new(track) }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment