Map VS Object Access

Benchmark created on


Setup

let map = new Map();
let obj = {};
let size = 5e6;

const benchMarkMapSet = size => {
for (let i = 0; i < size; i++) {
    map.set(i, i);
}
};

const benchMarkObjSet = size => {
for (let i = 0; i < size; i++) {
    obj[i] = i;
}
};

const benchMarkMapGet = size => {
for (let i = 0; i < size; i++) {
    let x = map.get(i);
}
};

const benchMarkObjGet = size => {
for (let i = 0; i < size; i++) {
    let x = obj[i];
}
};

Teardown

map = new Map();
obj = {};

Test runner

Ready to run.

Testing in
TestOps/sec
Map Set
benchMarkMapSet(size);
ready
Object Set
benchMarkObjSet(size);
ready
Map Get
benchMarkMapGet(size);
ready
Object Get
benchMarkObjGet(size);
ready

Revisions

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