Suggestion: Array.prototype.repeat

Herby Vojčík herby at mailbox.sk
Tue Jan 3 06:11:22 PST 2012


Sorry, fixed (you get the idea, anyway, doing 10 concats is worse than doing 
five of them, with _big_ chunks of data in the last calls). There is a 
checking throw in the end so it really works now.
Now it is even more faster :-)

Herby

-----Pôvodná správa----- 
From: felix
Sent: Tuesday, January 03, 2012 2:30 PM
To: Herby Vojčík
Cc: Rick Waldron ; Adam Shannon ; Mariusz Nowak ; es-discuss at mozilla.org
Subject: Re: Suggestion: Array.prototype.repeat

repeatD(10) returns 17 copies, not 10.

On Tue, Jan 3, 2012 at 4:28 AM, Herby Vojčík <herby at mailbox.sk> wrote:
> Hello,
>
> 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.
>
> Herby
>
> -----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
>
> http://jsperf.com/array-repeat/2
>
> 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() ).
>
> Rick
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss 



More information about the es-discuss mailing list