On 5/31/07, sur max <sur.max / gmail.com> wrote:
> Hey Meinrad,
>
> I never came across this fact earlier that WeakRef usage can lead to the
> performance loss..
> It will be great if you can provide some links justifying the same.

require "weakref"
require "benchmark"

a=Object.new

puts Benchmark.measure {
	1_000_000.times{ a.to_s }
}

b=WeakRef.new( Object.new )

puts Benchmark.measure {
	1_000_000.times{ b.to_s }
}

=>

  5.032000   0.031000   5.063000 (  5.297000)
 18.172000   0.047000  18.219000 ( 18.375000)

so as you see, the weakref is quite slow (almost factor 4) compared to
direct reference. maybe, if the number of objects in objectspace is
high it is even slower, but i don't know if that is really true. this
was measured with ruby 1.8.5.