From: "José Ignacio" Date: 2008-09-02T23:05:06+09:00 Subject: Re: Undo Object.extend Benchmarks come to save us: require 'benchmark' module Mod; def method; 3*50+1; end; end a = A.new; a.extend Mod b = A.new; b.extend Mod Benchmark.bm(30) do |x| x.report('Removing & extending (1)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (2)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (3)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (4)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (5)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (7)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (8)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (9)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('Removing & extending (10)') { 1000.times {b.remove(Mod); b.extend(Mod)} } x.report('a.method') { 5000000.times {a.method} } x.report('b.method') { 5000000.times {b.method} } end Output: user system total real Removing & extending (1) 0.040000 0.000000 0.040000 ( 0.044988) Removing & extending (2) 0.090000 0.000000 0.090000 ( 0.093711) Removing & extending (3) 0.130000 0.000000 0.130000 ( 0.132898) Removing & extending (4) 0.170000 0.000000 0.170000 ( 0.168743) Removing & extending (5) 0.210000 0.000000 0.210000 ( 0.214160) Removing & extending (7) 0.260000 0.010000 0.270000 ( 0.266014) Removing & extending (8) 0.330000 0.000000 0.330000 ( 0.327045) Removing & extending (9) 0.400000 0.000000 0.400000 ( 0.404618) Removing & extending (10) 0.520000 0.000000 0.520000 ( 0.519781) a.method 5.290000 1.140000 6.430000 ( 6.428015) b.method 5.080000 1.130000 6.210000 ( 6.390391) It's suprising, but removing and extending slows down increasingly, though there is no slow down in the method call (i.e. a & b have the same performance). I've tried to repeat the tests commenting out "super mod_clone" in Behaviourable.extend and now there's no slow down, so the performance issue is related with Object.extend. -- Posted via http://www.ruby-forum.com/.