Member Associative Array Syntax VS Dot Syntax

JavaScript performance comparison

Test case created by Parris and last updated

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var hash = {},
      n = 1000;
  
  function fill(n) {
    var i = 0;
    for (i; i < n; i++) {
      hash["name" + i] = i;
    }
  }
  
  if (typeof hash.name100 === "undefined") {
     fill(n);
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Dot Notation
var b = hash.name100;
pending…
Array Notation
var b = hash["name100"];
pending…
Concat with num
var b = hash["name" + 100];
pending…
Concat with strings
var b = hash["name" + "thing"];
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.

0 Comments