Wednesday
Sep052007
Pulling loop limits out of the loop
Wednesday, September 5, 2007 We get quite a nice speedup if we take loop limits outside of the loop, and make them local variables. For example:
for ( i = 0; i < 100000; i++ )
compared to:
var limit = 100000;
for ( i = 0; i < limit; i++ )
We get quite a nice speedup just because the loop limit becomes an astore/aload instead of a new object creation representing the limit. On a 10 second loop, we gained about 1 second.
tagged
JavaScript
JavaScript 
Reader Comments