Objects As Hashes (100k)

JavaScript performance comparison

Revision 2 of this test case created by Parris

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  //I would really only like to run fill hash once ever
  var testSpace = testSpace || {};
  testSpace.hash = window.hash || {};
  testSpace.n = 1000000;
  testSpace.random = Math.floor((Math.random() * testSpace.n) + 1);
  testSpace.variableName = "name" + testSpace.random; 
  testSpace.otherName = "other" + testSpace.random;
  
  function fill(n) {
    var i = 0;
    for (i; i < n; i++) {
      testSpace.hash["name" + i] = i;
    }
  }
  
  if (typeof testSpace.hash.name100 === "undefined") {
    fill(testSpace.n);
  }

};

Benchmark.prototype.teardown = function() {
  testSpace.random = Math.floor((Math.random() * testSpace.n) + 1);
  testSpace.variableName = "name" + testSpace.random;
  testSpace.otherName = "other" + testSpace.random;

};
</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
Destroy
delete testSpace.hash[testSpace.variableName];
pending…
Update
testSpace.hash[testSpace.variableName] = 1;
pending…
Create
testSpace.hash[testSpace.otherName] = 5;
pending…
Read
var b = testSpace.hash[testSpace.variableName];
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