Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
merge preformance compare 2
(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 p = { 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 b = { collateral: 'ASDG', askNotional: 1245, bidNotional: 3467, cumRealized: 5736, entryPrice: 23567, isolatedWallet: 23536, markPrice: 23678, notionalValue: 347345, positionSize: 3245247, unrealizedProfit: 3477, };
Tests:
lodash merge
var c = _.merge({}, a, p, b);
Object.assign
var c = Object.assign({}, a, p, b);
spread
var c = {...a, ...p, ...c};
immutable
var c = Immutable.merge(a, p, 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):
**What is tested on the provided JSON?** The provided JSON represents a JavaScript benchmark test case. It defines two objects, `a` and `b`, which contain various properties related to trading and finance data. The test then creates a third object, `c`, by merging `a`, `p`, and `b` using different methods: `_.merge` (from the Lodash library), `Object.assign()`, spread operator (`...`), and `Immutable.merge` (from the Immutable.js library). **Options compared** The test compares four options for merging objects: 1. **Lodash's `_merge()` function**: This method is a recursive function that merges two or more objects into one. 2. **`Object.assign()` method**: This method copies properties from one or more source objects to a target object. 3. **Spread operator (`...`)**: This syntax is used to create a new object by copying the properties of one or more source objects. 4. **Immutable.js's `merge()` function**: This method creates a new object that combines two or more existing objects. **Pros and Cons of each approach** Here are some pros and cons for each approach: * **Lodash's `_merge()` function**: + Pros: Recursively merges objects, handles nested properties, and is often faster than `Object.assign()`. + Cons: Can be slower than spread operator due to its recursive nature. * **`Object.assign()` method**: + Pros: Simple and straightforward, handles basic merging of objects. + Cons: Limited recursion depth (default 5), may not handle nested properties well. * **Spread operator (`...`)**: + Pros: Fast, simple, and easy to use. Handles basic merging of objects. + Cons: Only suitable for shallow object merges, does not handle nested properties. * **Immutable.js's `merge()` function**: + Pros: Creates a new immutable object that combines two or more existing objects. + Cons: May be slower than spread operator due to its creation of a new object. **Library usage and special JS features** The test case uses the following libraries: * Lodash.js (version 4.17.5) for its `_merge()` function * Immutable.js (version 4.3.4) for its `merge()` function There are no special JavaScript features used in this benchmark. **Alternatives to these approaches** If you want to implement a similar merge operation without using libraries, you can use the following alternatives: 1. **Manual recursive merging**: Write a custom recursive function that merges two or more objects. 2. **Using `Object.assign()` with multiple arguments**: Use `Object.assign()` with multiple arguments to merge multiple source objects into one target object. 3. **Using a library like Lo-Dash or Ramda**: Consider using another library that provides similar merging functionality. These alternatives may offer trade-offs in terms of performance, readability, and maintainability, so choose the approach that best fits your needs.
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 3
Comments
Confirm delete:
Do you really want to delete benchmark?