Objects As Hashes (1 mil)

JavaScript performance comparison

Test case created by Parris

Preparation code


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

};

Benchmark.prototype.teardown = function() {
  random = Math.floor((Math.random() * n) + 1);
  variableName = "name" + random;
  otherName = "other" + 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
Create
hash[otherName] = 5;
pending…
Read
var b = hash[variableName];
pending…
Update
hash[variableName] = 1;
pending…
Destroy
delete hash[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