felix8a at gmail.com
Tue Jan 3 05:30:51 PST 2012
repeatD(10) returns 17 copies, not 10.
On Tue, Jan 3, 2012 at 4:28 AM, Herby Vojčík <herby at mailbox.sk> wrote:
> binary ftw. See http://jsperf.com/array-repeat/4 Array.prototype.repeatD.
> And I also tried push.apply in repeatC (not to copy over the array using
> concat but grow it in place until possible) and it really surprised me it
> was that much slower. Concat is probably heavily optimized.
> -----Pôvodná správa----- From: Rick Waldron
> Sent: Tuesday, January 03, 2012 2:21 AM
> To: Adam Shannon
> Cc: es-discuss at mozilla.org ; Mariusz Nowak
> Subject: Re: Suggestion: Array.prototype.repeat
> On Mon, Jan 2, 2012 at 5:55 PM, Adam Shannon <adam at ashannon.us> wrote:
> Another thing to think about is that .repeat (both on String and
> Array) will be used a lot in production. So it would make sense for
> each solution to be optimized for their specific case. It doesn't make
> sense to slow down something as trivial as .repeat()
> Creating a 10000 item array by repeating a 1000 item array 10 times, the
> difference is negligible when compared the implementation that I wrote, not
> the one given above
> Also, note that I had to "make up" my own Array.repeat() because the
> Array.generate shown above did not create the same return as the initial
> Array.prototype.repeat(), but I stuck to the concepts laid out - no new
> array is initialized (except that Array.prototype.slice _does_ initialize a
> new Array() ).
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss