Object Merge Performance Test

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Setup

const baseAttributes = { a: 1, b: 2, c: 3 };
const utmParams = { d: 4, e: 5 };
const rest = { f: 6 };
const extension = { g: 7 };
const eventTimestamp = { h: 8 };

// 병합할 객체 리스트
const testData = [baseAttributes, utmParams, rest, extension, eventTimestamp];

// 사용자 정의 Shallow Merge 함수
function mergeAttributes(target, ...sources) {
  for (const source of sources) {
    if (source) {
      for (const key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
  }
  return target;
}

Test runner

Ready to run.

Testing in
TestOps/sec
사용자 정의 mergeAttributes
mergeAttributes({}, ...testData);
ready
Lodash _.merge()
_.merge({}, ...testData);
ready

Revisions

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