Reading Performance of ES6 Map vs Object properties (v56)

Revision 56 of this benchmark created on


Description

Compare reading performance of native Map implementation vs using an object as a hash map.

Setup

var map = new Map();
    var obj = {};
    var hashSize = 10000;
    var testKeyNum = 20;
    var testkeys = [];
    
    for (var i = 0; i < hashSize; i++) {
        var key = randomString();
        var val = randomString();
        map.set(key, val);
        obj[key] = val;
    }
    
    var keys = Array.from(map.keys());
    for (var i = 0; i < testKeyNum; i++) {
        var testkey = keys[Math.random()*hashSize >>> 0];
        testkeys.push(testkey);
    }
    
    function randomString() {
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    
        for( var i=0; i < 5; i++ )
            text += possible.charAt(Math.floor(Math.random() * possible.length));
    
        return text;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
map.get(key)
for (var i = testkeys.length - 1; i >= 0; i--) {
  map.get(testkeys[i]);
}
ready
obj[key]
for (var i = testkeys.length - 1; i >= 0; i--) {
  obj[testkeys[i]];
}
ready

Revisions

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