For Loop

JavaScript performance comparison

Revision 80 of this test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
</script>
<script>
  var underscore = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js">
</script>
<script>
  var lodash = _.noConflict();
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
  var arr = underscore.range(1,1000);
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
while loop that imitates a for loop
var i = 0;
while (i < arr.length) {
  arr[i]=i;
  i++;
};
pending…
while loop that imitates a for loop, caching the length
var i = 0,
    len = arr.length;
while (i < len) {
  arr[i]=i;
  i++;
};
pending…
Reverse while loop
var i = arr.length;
while (i--) {
  arr[i]=i;
};
pending…
Reverse while loop without implicit ToBoolean
var i = arr.length;
while (i-- > 0) {
  arr[i]=i;
};
pending…
Reverse do … while loop
var i = arr.length;
do {
  arr[i]=i;
} while (i--);
pending…
Reverse for loop
for (var i = arr.length; i--;) {
  arr[i]=i;
};
pending…
Standard Loop
var i
for (i = 0; i < arr.length; i++) {
  arr[i]=i
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment