Skip to content

Instantly share code, notes, and snippets.

@takkanm
Created June 30, 2016 08:41
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 takkanm/1928ee008d337883ba6191a13dad75dd to your computer and use it in GitHub Desktop.
Save takkanm/1928ee008d337883ba6191a13dad75dd to your computer and use it in GitHub Desktop.
require 'benchmark'
module Foo
end
times = 1_000_000
Benchmark.bm 30 do |r|
r.report 'extend' do
times.times do
o = Object.new
o.extend Foo
end
end
GC.start
r.report 'singleton_class include' do
times.times do
o = Object.new
o.singleton_class.include Foo
end
end
GC.start
r.report 'singleton_class prepend' do
times.times do
o = Object.new
o.singleton_class.include Foo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment