Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from fxn/gist:7572692
Last active Dec 28, 2015
Embed
What would you like to do?
require 'benchmark'
TIMES = 10_000_000
module M
X = ''
module N
module A
module B
def self.x
X
end
end
end
end
end
Benchmark.bm do |x|
x.report("constant") { TIMES.times { ::M::N::A::B.x }}
x.report("literal") { TIMES.times { '' }}
x.report("frozen") { TIMES.times { ''.freeze }}
end
__END__
[aaron@higgins git]$ ruby -v gistfile1.rb
ruby 2.1.0dev (2013-11-16 trunk 43688) [x86_64-darwin12.5.0]
user system total real
constant 0.870000 0.000000 0.870000 ( 0.878663)
literal 1.210000 0.000000 1.210000 ( 1.206898)
frozen 0.510000 0.000000 0.510000 ( 0.509119)
[aaron@higgins git]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment