By using (in Array & Index) this form

    var list2 = new Array(max);

you are letting Javascript know early, how big the array needs to be.  If 
it understands and allocates the whole array *once*, then there is no more 
memory allocation work to be done, just code running.

Doing this (Haxxor & Index)

    list3[max] = "thing";

is not the same thing, because Javascript can have "sparse arrays", where 
there are huge gaps of 'nothing' (no elements allocated) in arrays.  
Filling up the array would still require memory allocations. 

"Push" may actually be adding large memory allocation chunks at the end of 
the array, and so minimizing some work.  (i.e. "Hmm, he added 500 so far, 
so let's expand by at least that much on the next push")

Does the reminder that the biggest drain on code speed can be the work 
behind the scenes, help?

On Wednesday, February 29, 2012 9:29:43 PM UTC-6, Scott González wrote:
>
> Does anyone know the reason for the massive differences in this perf test? 
> http://jsperf.com/arraytests/2
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to