Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from fxn/gist:7572692
Last active December 28, 2015 22:49
Show Gist options
  • Save tenderlove/7573807 to your computer and use it in GitHub Desktop.
Save tenderlove/7573807 to your computer and use it in GitHub Desktop.
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 gistfile1.rb
user system total real
constant 0.890000 0.000000 0.890000 ( 0.892681)
literal 1.200000 0.000000 1.200000 ( 1.202642)
frozen 0.520000 0.000000 0.520000 ( 0.516941)
[aaron@higgins git]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment