Re: [JSMentors] Pushing to Arrays

2011-03-22 Thread Tony Wang
I think it's very important to find a better optimizing way for Array in different situation, your application Performance could be consist of Array over 30% . (Array used anywhere!) (For example , if you are using jQuery , it means you are facing a lot of Dom Arrays) And we usually use Array

Re: [JSMentors] Pushing to Arrays

2011-03-20 Thread אריה גלזר
IMO this is a very good example of over optimizing. Choose the one that's most readable and shorter to write (= push() ). Array performance is simply not something you should care about in 99% of JS apps. Unless you actually find yourself pushing 10K items into an array (in which case it's almost

Re: [JSMentors] Pushing to Arrays

2011-03-20 Thread Diego Perini
On Sun, Mar 20, 2011 at 7:29 AM, אריה גלזר arieh.gla...@gmail.com wrote: IMO this is a very good example of over optimizing. Choose the one that's most readable and shorter to write (= push() ). Array performance is simply not something you should care about in 99% of JS apps. Unless you

[JSMentors] Pushing to Arrays

2011-03-16 Thread Josi
Can somebody explain this behaviour? http://jsperf.com/array-push Why it is better to use a function instead of direct access? -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive,

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Rob Griffiths
Why it is better to use a function instead of direct access? It's not always better. Push is far better when you're not sure what the next index of your array is. for example: [87, 2, 369, , , , 42, 53] If i remember correctly .length will return 5, which means if you started adding in

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Nick Morgan
Length should return the value of the last index + 1, so in that case length will return 8: http://jsfiddle.net/ http://jsfiddle.net/.length is defined that way so you can safely use it to iterate over all the elements of an array with a for loop. AFAIK, `arr[arr.length] = x;` is functionally

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Rob Griffiths
Length should return the value of the last index + 1, so in that case length will return 8 I knew I should have checked before stating that. -- Rob Griffiths http://bytespider.eu @bytespider http://twitter.com/bytespider https://github.com/bytespider -- To view archived discussions from

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Peter van der Zee
On Thu, Mar 10, 2011 at 3:55 PM, Josi mich...@josi.de 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

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Diego Perini
On Wed, Mar 16, 2011 at 12:14 PM, Rob Griffiths r...@bytespider.eu wrote: Length should return the value of the last index + 1, so in that case length will return 8 I knew I should have checked before stating that. -- Rob Griffiths http://bytespider.eu @bytespider

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Tony Wang
btw ,there's a interesting topic ,too. if you are doing array concat job, you could take a look for this. http://jsfiddle.net/We9p9/1/ The keypoint is , even when you are using array.push , *ary.push(1,2,3,4,5);* is still faster then *ary.push(1); ary.push(2); ary.push(3); ary.push(4);

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Tony Wang
Oops , I find this script is too heavy for my ie8 but it's fine for firefox. (that's just like what we know ) Don't click it if you are using IE. haha This is a smaller amount version. http://jsfiddle.net/We9p9/3/ And the speed still very depends on your browser implemention between