Twitter
Essays
Random
« Javascript Interpreter in Javascript | Main | Publications »
Wednesday
Sep052007

Pulling loop limits out of the loop

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.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>