Le 1/6/2005, "Nikolai Weibull"
<mailing-lists.ruby-talk / rawuncut.elitemail.org> a rit:
>Gyoung-Yoon Noh wrote:
>
>> Some non-destructive methods are usually implemented by
>> simply copying reference after calling destructive method.
>
>And some arent.  Anyway, Ive had gsub! be a lot slower than gsub in
>benchmarks.  Still, some destructive methods will by their very
>definition be faster.
>
>>                       user     system      total        real
>> Destructive       2.930000   0.000000   2.930000 (  2.935663)
>> Non-destructive   3.170000   0.010000   3.180000 (  3.171050)
>
>Id say that a time-difference of 0.000235 seconds per call to
>String#sort!.reverse! versus String#sort.reverse doesnt warrant
>destructive methods on strings (in this benchmark anyway),

For Strings the performance penalty is typically negligible (it
may not be so for all classes). But consider this:

class Foo
  def initialize
    @a = 5
  end

  attr_accessor :a
end

foo = Foo.new
foo.a = 6

Current behaviour aside, should the last line create a new Foo object?

>        nikolai

E

--
template<typename duck>
void quack(duck& d) { d.quack(); }