approach 1 vs 2

Benchmark created on


Setup

let templateTypeListArr = Array.from({length: 5000}, ()=>{return {id:'id', name:'name'}});

Test runner

Ready to run.

Testing in
TestOps/sec
v1
const templateTypeListMap = templateTypeListArr.reduce(
            (obj, item) => ({...obj, [item.id]: item.name}),
            {}
        );
ready
v2
const templateTypeListMap = {};
templateTypeListArr.forEach((item)=>{
	templateTypeListMap[item.id]
 = item.name})
ready

Revisions

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