For In Versus For Versus For Length Cached

JavaScript performance comparison

Test case created by Vaughn

Preparation code

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

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;
For Loop
for (var i = 0; i < thingy.length; i++) {
  thingy2 = i;
For Loop (Length Cached)
len = thingy.length;
for (var i = 0; i < len; i++) {
  thingy2 = i;

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment