object maps -- map vs object vs struct (v8)

Revision 8 of this benchmark created on


Description

add set

Setup

var a = 1;
    var b = 2.15923;
    var c = 0xFFFFFF | 0;
    var d = 'asdf';
    var e = 'i should be undefined';
    
    function MapStruct(a, b, c, d) {
      this[a] = a;
      this[b] = b;
      this[c] = c;
      this[d] = d;
    };
    
    var noproto = Object.create(null);
    noproto[a] = a;
    noproto[b] = b;
    noproto[c] = c;
    noproto[d] = d;
    
    var obj = {};
    obj[a] = a;
    obj[b] = b;
    obj[c] = c;
    obj[d] = d;
    
    if (typeof Map !== "undefined") {
      var map = new Map();
      map.set(a, a);
      map.set(b, b);
      map.set(c, c);
      map.set(d, d);
    }
    
    if (typeof Set !== "undefined") {
      var set = new Set();
      set.add(a);
      set.add(b);
      set.add(c);
      set.add(d);
    }
    
    var struct = new MapStruct(a, b, c, d);

Test runner

Ready to run.

Testing in
TestOps/sec
obj property lookup
obj[a];
obj[b];
obj[c];
obj[d];
obj[e];
ready
struct property lookup
struct[a];
struct[b];
struct[c];
struct[d];
struct[e];
ready
map lookup 1
map.get(a);
map.get(b);
map.get(c);
map.get(d);
map.get(e);
ready
obj property lookup (safe)
obj.hasOwnProperty(a) && obj[a];
obj.hasOwnProperty(b) && obj[b];
obj.hasOwnProperty(c) && obj[c];
obj.hasOwnProperty(d) && obj[d];
obj.hasOwnProperty(e) && obj[e];
ready
obj property lookup (very safe)
Object.hasOwnProperty.call(obj, a) && obj[a];
Object.hasOwnProperty.call(obj, b) && obj[b];
Object.hasOwnProperty.call(obj, c) && obj[c];
Object.hasOwnProperty.call(obj, d) && obj[d];
Object.hasOwnProperty.call(obj, e) && obj[e];
ready
struct property lookup (safe)
struct.hasOwnProperty(a) && struct[a];
struct.hasOwnProperty(b) && struct[b];
struct.hasOwnProperty(c) && struct[c];
struct.hasOwnProperty(d) && struct[d];
struct.hasOwnProperty(e) && struct[e];
ready
struct property lookup (very safe)
Object.hasOwnProperty.call(struct, a) && struct[a];
Object.hasOwnProperty.call(struct, b) && struct[b];
Object.hasOwnProperty.call(struct, c) && struct[c];
Object.hasOwnProperty.call(struct, d) && struct[d];
Object.hasOwnProperty.call(struct, e) && struct[e];
ready
obj no prototype property lookup
noproto[a];
noproto[b];
noproto[c];
noproto[d];
noproto[e];
ready
set
set.has(a);
set.has(b);
set.has(c);
set.has(d);
set.has(e);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.