Object vs Map

Benchmark created on


Setup

const a = {
    Error: '10',
    Assert: '20',
    Warning: '30',
    Log: '40',
    Exception: '50',
}

const m = new Map([
    ['Error', '10'],
    ['Assert', '20'],
    ['Warning', '30'],
    ['Log', '40'],
    ['Exception', '50']
])

Test runner

Ready to run.

Testing in
TestOps/sec
Object
const temp1 = a['Warning'] ?? ''
const temp2 = a['Ok'] ?? ''
const temp3 = a['Exception'] ?? ''
console.log(temp1, temp2, temp3)
ready
Map
const temp1 = m.get('Warning') ?? ''
const temp2 = m.get('Ok') ?? ''
const temp3 = m.get('Exception') ?? ''
console.log(temp1, temp2, temp3)
ready

Revisions

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