Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
merge preformance compare 3
(version: 0)
Comparing performance of:
lodash merge vs Object.assign vs spread vs immutable
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/immutable/4.3.4/immutable.min.js'></script>
Script Preparation code:
var a = { lastPrice: '1234.345', contractVal: 109, marginAsset: 'GET', baseAsset: 'ASG', quoteAsset: 'ASFE', quantityPrecision: 8, pricePrecision: 4, equalQtyPrecision: 6, tickSize: 0.001, limitStepSize: 0.001, marketStepSize: 0.01, }; var b = { adl: 1234, askNotional: 2345236, bidNotional: 34636, collateral: 'AFE', marginAsset: 'EJG', cumRealized: 142565, entryPrice: 2356, id: '3452562', isolated: true, isolatedWallet: 1225, leverage: 23, markPrice: 34346, lastPrice: 567458, initialMarkPrice: 23456, notionalValue: 345346, positionSize: 45748, positionSide: 'ASGO', symbol: 'ASGT', unrealizedProfit: 1235, selectPrice: 12345, pushTime: 12435634578 } var c = { collateral: 'ASDG', askNotional: 1245, bidNotional: 3467, cumRealized: 5736, entryPrice: 23567, isolatedWallet: 23536, markPrice: 23678, notionalValue: 347345, positionSize: 3245247, unrealizedProfit: 3477, };
Tests:
lodash merge
var d = _.merge({}, a, b, c);
Object.assign
var e = Object.assign({}, a, b, c);
spread
var f = {...a, ...b, ...c};
immutable
var g = Immutable.merge(a, b, c);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash merge
Object.assign
spread
immutable
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):
I'd be happy to explain what's being tested in this benchmark. **Benchmark Overview** The benchmark compares the performance of three different approaches for merging objects: 1. `_.merge()` from the Lodash library 2. `Object.assign()` 3. Spread syntax (`{...obj1, ...obj2, ...obj3}`) **Options Compared** Each test case uses a similar input object (`a`, `b`, and `c`) to compare the performance of each approach. * `_.merge()` takes three objects as arguments and returns a new object with the merged properties. * `Object.assign()` takes an array of objects and returns a new object with the merged properties. In this case, it's used with three objects using the spread syntax (`{...obj1, ...obj2, ...obj3}`). * Spread syntax uses the `{...obj1, ...obj2, ...obj3}` syntax to merge three objects into one. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: * `_.merge()`: Pros: + Can handle nested objects. + Often faster than spread syntax for large datasets. Cons: + May not be as familiar to developers without Lodash knowledge. + Requires an external library (Lodash). * `Object.assign()`: Pros: + Widely supported and familiar to most developers. + No external libraries required. Cons: + Can be slower than spread syntax for large datasets. + Does not handle nested objects as easily as `_.merge()`. * Spread syntax: Pros: + Fast and efficient, especially for small datasets. + Easy to understand and use, even for developers without Lodash knowledge. Cons: + May not work correctly with nested objects. + Can be slower than `_.merge()` for very large datasets. **Library: Immutable** The "Immutable" test case uses the Immutable library to merge three objects. Immutable is a JavaScript library that provides immutable data structures, which can help improve performance by reducing unnecessary reassignments of variables. **Special JS Feature/ Syntax: None** There are no special JavaScript features or syntax used in this benchmark. **Other Alternatives** If you're interested in exploring alternative approaches for merging objects, here are some other options: * Using `JSON.stringify()` and `JSON.parse()`: This approach can be slow and may not work correctly with nested objects. * Using a custom loop to iterate through the properties of each object: This approach can be verbose and may not be as efficient as the other options. Keep in mind that the performance differences between these approaches will depend on the specific use case and dataset size.
Related benchmarks:
Angular 1.7.5 Copy vs Lodash 4.17.11 Clone Deep
Angular Copy vs Lodash Copy (large-ish data)
merge preformance compare
merge preformance compare 2
Comments
Confirm delete:
Do you really want to delete benchmark?