jsbench003

A little tip if you like 'for' loops
function f1 the y loop verifies that y is < array.length before terminating y < array.length is tested for every loop cycle (600000 times in this test) function f2 the y loop evalutes array.length only once... the end condition is y < yEnd
It is very common to see things of this kind var array=[....] for (var i=0;y<array.length;i++) { but this is not good since array.length is evaluated at the end of each cycle for the entire loop. So remember to create lookup vars if you are using objects or arrays inside loops. f1 took:161ms f2 took:146ms [FF 3.5.2]
Conclusion: use this tecnique in Javascript 'for' loops for (var i=0,iEnd=array.length;i<iEnd;i++) {

Leave a Reply

 (required)

plain