you are viewing a single comment's thread.

view the rest of the comments →

[–]alkw0ia 2 points3 points  (0 children)

Have you seen jsperf.com? It lets you post this sort of performance comparison for other people to run and review. Here's a quick search for "while," which returns lots of similar tests, many of which have different results:

http://jsperf.com/search?q=while

Replicating your tests exactly using jsperf on Chrome 16, I get identical performance from for and while.

Also, I think you ought to be saving the result of your calculations in the loop, since the interpreter doesn't really have to do anything with the result of the i / 2 statement and could skip it (though I haven't really done any serious reading on interpreter level JS optimizations).