Skip to content

Instantly share code, notes, and snippets.

@fxn
Last active December 28, 2015 22:39
Show Gist options
  • Save fxn/7572692 to your computer and use it in GitHub Desktop.
Save fxn/7572692 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 { '' }}
end
__END__
fxn@yeager:~/tmp $ ruby foo.rb
user system total real
constant 0.970000 0.000000 0.970000 ( 0.974618)
literal 1.170000 0.010000 1.180000 ( 1.173427)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment