Map vs Object as hashes

JavaScript performance comparison

Revision 2 of this test case created by Rahly

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var obj = {},
    map = new Map,
    hop = Object.prototype.hasOwnProperty
  for (var i = 0; i < 100000; i++) {
    obj[i] = true
    map.set(i, true)
  }

};
</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
get (Object)
hop.call(obj, 10) ? obj[10] : undefined // true
hop.call(obj, 'ok') ? obj['ok'] : undefined // false
hop.call(obj, 99999) ? obj[99999] : undefined // true
hop.call(obj, 2398413984) ? obj[2398413984] : undefined // false
pending…
get (Map)
map.get(10) // true
map.get('ok') // undefined
map.get(99999) // true
map.get(2398413984) // undefined
pending…
get (Map) 2
map[10];
map['ok'];
map[99999];
map[2398413984];
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