Nikolai Weibull wrote:
> 
> Well, with slice!, you have to do more work than doing a slice.  The
> reason is that you have to paste together the parts that are still a
> part of the string.  With slice you simply return the substring.

Seems to me that the same logic should apply to gsub vs. gsub!, but it 
doesn't quite work out that way.  A gsub benchmark using different 
lengths of input and output might be more appropriate.

An aside: I do not accept the assertion that Strings should only be used 
when they can be kept short.  I still expect reasonably good performance 
when operating on large pieces of text all at once, e.g. a large file or 
some other text-based data such as MIME or XML data.

> A comment on your benchmark: doesn't it make more sense to do the tests
> on new strings each time?

For the destructive methods, definitely.  For the non-destructive 
methods, it's irrelevant.

> Anyway, if you don't like this test, here are the times on my machine
> (it seems Ruby on a Linux system runs a lot faster than on a Windows
> system, and much more evenly between the two versions of each method):
<snip>
> I'm not arguing with the fact that for most methods, the destructive
> version will be faster.  I'm just saying that the performance difference
> between the two isn't that big,

I still see a lot of cases in your results where the destructive method 
is roughly twice as fast.  That is significant.

-- 
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoil.com/>