For In Versus For Versus For Length Cached

JavaScript performance comparison

Test case created by Vaughn

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var thingy = [1, "test", 44, true, false, "tester", 212313213, "testestetestetest stest ,...!", 2, true];
    var thingy2;
    var len;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
For In
for (var i in thingy) {
  thingy2 = i;
}
pending…
For Loop
for (var i = 0; i < thingy.length; i++) {
  thingy2 = i;
}
pending…
For Loop (Length Cached)
len = thingy.length;
for (var i = 0; i < len; i++) {
  thingy2 = 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