Javascript looping performances
I’ve done a lot of javascript programming recently and more then one time, I had to tweek performance. A nice test suite for performance testing of all (or at least a lot of) ways of looping through an array is located there: http://blogs.sun.com/greimer/resource/loop-test.html. That Blogentry for this awaits you here: http://blogs.sun.com/greimer/entry/best_way_to_code_a
Should be useful from time to time and I really shoud stop using those comfortable for-in-loops…
Addition:
Also is the inverted version of the reversed while loop faster than the ordinary cached for loop.
In short: for (var i=0, len=arr.length; i<len; i++) { } == 5 ms
var i = arr.length-1, j=0; while(--i) {++j;}; == 7 ms
Both tested on my 1.6 Ghz Notebook in battery mode with a simple array with 100,000 entries.
Subscrive all weblog entries.


