From: Florian Frank Date: 2004-04-21T17:10:09+09:00 Subject: Re: efficient collect+compact ? On 2004-04-21 11:31:03 +0900, Daniel Sheppard wrote: > Actually, using inject is much less efficient. When using that method, > the size of the array in unknown and has to be constantly increased, > leaving you with a big overhead of calls for memory allocation. That cannot be the reason why your test of inject was sooo slow, because you have never put anything into that array in your test. You have overwritten it with nil instead. The C-implementation of inject seems to be pretty slow compared with the other methods, because it calls a lot of functions under the hood. :-( This all was made worse by the fact that inject calls rb_gc_force_recycle after every call and you made 1000(!) of them. The results will be much closer to each other, especially for the small test values, if you call GC.start after the proc.call in your times loop. Anyway, I like inject - it can do miracles! ;) -- #!/bin/sh # Hello! I'm a signature virus! Execute me and watch me spread! s=.signature; cat $0 >/tmp/$s && mv /tmp/$s $s && chmod a+x $s