object vs array of object

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var list1 = {
      "AAPL": "Apple Inc.",
      "GOOG": "Google Inc.",
      "INTC": "Intel Corporation"
    };
   
    var list2 = [{
      "ticker": "AAPL",
      "name": "Apple Inc."
    }, {
      "ticker": "GOOG",
      "name": "Google Inc."
    }, {
      "ticker": "INTC",
      "name": "Intel Corporation"
    }];
   
    function go(element) {
      var data = {
        'ticker': element.ticker,
        'name': element.name,
      };
      console.log(data);
    }
};
</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
list1
for (key in list1) {
  var data = {
    'ticker': key,
    'name': list1[key]
  }
  console.log(data);
}
pending…
list2
list2.forEach(go)
pending…
list2 for loop
for (var i = 0, len = list2.length; i < len; i++) {
  var entry = list2[i];
  var data = {
    'ticker': entry.ticker,
    'name': entry.name,
  };
  console.log(data);
}
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