Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created April 12, 2016 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/e7d47a84a6ded1768a1a7dae8a742116 to your computer and use it in GitHub Desktop.
Save tenderlove/e7d47a84a6ded1768a1a7dae8a742116 to your computer and use it in GitHub Desktop.
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