On Thu, Mar 10, 2011 at 3:55 PM, Josi <[email protected]> wrote:

> Can somebody explain this behaviour?
>
> http://jsperf.com/array-push
>
> Why it is better to use a function instead of direct access?


It's not per se, although some browsers can optimize patterns they
recognize. (If you somehow mess with Array.prototype.push you might notice
different results.)

Note that the test is comparing incremental array access opposed to
decremental array access. While reading is not so much a problem,
the writing in the decremental loop will cause a huge sparse array (= not
all places of the array are used). I've seen an article (sorry, don't know
where) showing browsers have really different (and surprising) performance
results when it comes to sparse arrays.

(The third revision of that jsperf has a test which is a better comparison
to .push though, with similar results, so maybe it's no longer relevant)

- peter

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to