Created
April 12, 2016 00:51
-
-
Save tenderlove/e7d47a84a6ded1768a1a7dae8a742116 to your computer and use it in GitHub Desktop.
This file contains 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' | |
class Foo | |
def bar; end | |
end | |
singleton = (100_000 * 20).times.map do |i| | |
foo = Foo.new | |
foo.singleton_class | |
foo | |
end | |
no_singleton = (100_000 * 20).times.map do |i| | |
foo = Foo.new | |
#foo.singleton_class | |
foo | |
end | |
GC.disable | |
p :no_singleton => Benchmark.realtime { no_singleton.each { |foo| foo.bar } } | |
p :singleton => Benchmark.realtime { singleton.each { |foo| foo.bar } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment