Lately I've been really digging into JS performance, and this other question of mine Javascript Array Performance lead me to this problem.
Problem: Looping using a global variable seems to be WAY faster than iterating using a local variable, can anyone explain to me, why is that ? --- This has just been my error in JSPerf understanding, but Problem 2 still remains, but I guess there is no real answer to it, the rest has been discussed with @Igor-Raush in chat --- Or so I thought, that test in JSPerf is still 100x faster, then the basic version ...
- I am pretty sure it isn't local variable creation
You can see this behavior here: http://jsperf.com/fastest-array-loops-in-javascript/420 -- I added the last two tests, but the last one did not work, for some reason, so I removed its contents
Problem 2 (extra question, kind of related): Why is that when you run the tests on JSPerf individually ( for some of them ), their performance is consistently COMPLETELY different, than when they are all ran at once ? ( You can see this on While length-- test )
I am testing this, because ( If you went to my other question ), I do not believe that looping over my array should be as slow as it is, in the tests.