Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Merging deeply nested objects
(version: 0)
Comparing performance of:
Custom vs Lodash
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Tests:
Custom
const a = { firstParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } }, secondParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } }, thirdParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { uuid1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } } } const b = { firstParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } }, secondParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } }, thirdParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } } } function merge(target, source) { // The goal is to recreate _.merge // target is the object to be modified // source is the object to be merged // This is a recursive function, as the // source and target object can be deeply nested // eg: source = { a: { b: { c: 1 } } } // target = { a: { b: { d: 2 } } } // result = { a: { b: { c: 1, d: 2 } } } const recurse = (r_target, r_source) => { // Loop through the source object const r_sourceKeys = Object.keys(r_source ?? {}); for (let i = 0; i < r_sourceKeys.length; i++) { const key = r_sourceKeys[i], value = r_source[key]; const r_value = r_target[key]; if (typeof r_value !== 'object') // add the value to the target object r_target[key] = value; // Recurse if the key is an object if (typeof r_source[key] === 'object') recurse(r_target[key], r_source[key]); } return r_target; } return recurse(target, source); } merge(a, b)
Lodash
const a = { firstParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } }, secondParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } }, thirdParam: { x: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, y: { uuid1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], }, z: { id1: ["somedata1", "somedata2"], id3: ["somedata1", "somedata2"], } } } const b = { firstParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } }, secondParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } }, thirdParam: { x: { id2: ["somedata1", "somedata2"] }, y: { id2: ["somedata1", "somedata2"] }, z: { id2: ["somedata1", "somedata2"] } } } _.merge(a, b)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Custom
Lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
To answer this question, I'll need to analyze the provided code snippets and benchmark results. The code snippet appears to be a JavaScript object with nested properties, which seems to be related to data merging or concatenation. The benchmark result shows two test runs: "Custom" and "Lodash". The "Custom" test run has a higher number of executions per second (194526.03125) compared to the "Lodash" test run (60334.6796875). Based on this information, I'll assume that the task is to compare the performance of two different methods for merging or concatenating data. Since the actual implementation details are not provided, I'll need to make an educated guess about the purpose of the code snippet and benchmark results. Assuming the goal is to identify a more efficient method for merging or concatenating data, I would suggest that using Lodash's `merge` function (as shown in the original code snippet) might be less efficient compared to the custom implementation (indicated by the higher number of executions per second in the "Custom" test run). Therefore, my answer would be: **The most efficient method for merging or concatenating data is likely a custom implementation.** However, please note that this answer is based on limited information and might not reflect the actual requirements or expectations of the project. More context or details about the specific use case would be necessary to provide a more accurate answer.
Related benchmarks:
Merge list of objects
Merge objects
lodash merge vs deepmerge (updated)
lodash merge vs deepmerge (updated FIXED)
Lodash merge vs mergedeep 1
Comments
Confirm delete:
Do you really want to delete benchmark?