Array Caching

JavaScript performance comparison

Test case created by Joshua Kehn

Preparation code

<script>
  var arr = [{
   name: 'Test',
   age: 20,
   fav: "blue",
   hat: "one",
   sock: "two",
   other: "five",
  },
  {
   name: 'Test',
   age: 20,
   fav: "blue",
   hat: "one",
   sock: "two",
   other: "five",
  },
  {
   name: 'Test',
   age: 20,
   fav: "blue",
   hat: "one",
   sock: "two",
   other: "five",
  },
  {
   name: 'Test',
   age: 20,
   fav: "blue",
   hat: "one",
   sock: "two",
   other: "five",
  },
  {
   name: 'Test',
   age: 20,
   fav: "blue",
   hat: "one",
   sock: "two",
   other: "five",
  }];
</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
No Caching
var l = arr.length;
var comp = "";
while (l--) {
 comp += " " + arr[l].name + ":" + arr[l].age + arr[l].fav + arr[l].hat + arr[l].sock + arr[l].other;
 comp += " " + arr[l].name + ":" + arr[l].age + arr[l].fav + arr[l].hat + arr[l].sock + arr[l].other;
 comp += " " + arr[l].name + ":" + arr[l].age + arr[l].fav + arr[l].hat + arr[l].sock + arr[l].other;
}
pending…
Cached
var l = arr.length;
var comp = "";
while (l--) {
 var item = arr[l];
 comp += " " + item.name + ":" + item.age + item.fav + item.hat + item.sock + item.other;
 comp += " " + item.name + ":" + item.age + item.fav + item.hat + item.sock + item.other;
 comp += " " + item.name + ":" + item.age + item.fav + item.hat + item.sock + item.other;
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment