Created
April 3, 2015 07:46
-
-
Save korun/69a0ed0a89cafda3c269 to your computer and use it in GitHub Desktop.
ruby const_get vs ::
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
require 'benchmark' | |
n = 1_000_000 | |
class Parent | |
HANDLER_METHOD = :awesome_method | |
end | |
class Children < Parent | |
HANDLER_METHOD = :not_very_awesome_method | |
end | |
ch = Children.new | |
Benchmark.bmbm 20 do |results| | |
results.report 'cycle' do | |
n.times do | |
end | |
end | |
results.report 'class.const_get' do | |
n.times do | |
ch.class.const_get(:HANDLER_METHOD) | |
end | |
end | |
results.report 'class::' do | |
n.times do | |
ch.class::HANDLER_METHOD | |
end | |
end | |
end |
Author
korun
commented
Apr 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment