Created
December 14, 2016 06:15
-
-
Save fadhlirahim/8235b245522acdaf734ead321df02c1d to your computer and use it in GitHub Desktop.
Module.get_const vs Object.get_const vs Rails constantize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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