Map 성능비교 테스트

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
O(n2) : reduce + findIndex
const testData = Array.from({length: 365 * 3}).map((_,i) => ({key: i}));

const list = testData.reduce((result, item) => {
    const sameKeyIndex = result.findIndex(({key}) => key === item.key);


    if (sameKeyIndex === -1) {
        result.push(item);
    }

    return result;
}, []);
ready
O(n) : forEach + Map
const testData = Array.from({length: 365 * 3}).map((_,i) => ({key: i}));

const map = new Map();

testData.forEach((item) => {
    const sameKeyItem = map.get(item.key);

    if(!sameKeyItem){
        map.set(item.key, item);
    }
});

const list = Array.from(map.values());
ready

Revisions

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