From: Joel VanderWerf Date: 2007-11-03T11:25:15+09:00 Subject: Re: ActAsHash Marcin Raczkowski wrote: > Joel VanderWerf wrote: >> Marcin Raczkowski wrote: >>> self.instance_variable_get(("@"+index.to_s).to_sym) >> >> ISTR that "@"+index.to_s is slower than "@#{index}". > i think concantation is faster then creating new one and i have no idea > what ISTR mean Eh. It's not as much as I remembered: require 'benchmark' Benchmark.bmbm(12) do |bm| n = 1_000_000 index = "foo" @foo = 123 bm.report('"@"+index.to_s') do n.times do instance_variable_get("@"+index.to_s) end end bm.report('"@#{index}"') do n.times do instance_variable_get("@#{index}") end end end __END__ Rehearsal -------------------------------------------------- "@"+index.to_s 1.170000 0.010000 1.180000 ( 1.178025) "@#{index}" 0.960000 0.000000 0.960000 ( 0.954115) ----------------------------------------- total: 2.140000sec user system total real "@"+index.to_s 1.170000 0.000000 1.170000 ( 1.174559) "@#{index}" 0.940000 0.000000 0.940000 ( 0.945398) ISTR that ISTR means I seem to recall, but I might be wrong ;) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407