Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash assign vs object.assign vs spread
(version: 0)
Comparing performance of:
lodash assign vs object.assign vs spread
Created:
8 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>
Tests:
lodash assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.assign(a, b);
object.assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = Object.assign(a, b);
spread
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = { ...a, ...b };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash assign
object.assign
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash assign
4462793.0 Ops/sec
object.assign
6402160.5 Ops/sec
spread
18746944.0 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark tests the performance of three different methods for merging JavaScript objects: * **`lodash.assign()`:** This method uses the Lodash library, a popular collection of utility functions for JavaScript. Lodash is known for its efficiency and wide range of functionalities. * **`Object.assign()`:** This is a native JavaScript method available since ES6 (ECMAScript 2015) for merging objects. It's generally considered performant and widely supported. * **The spread operator (`...`)**: Introduced in ES6, the spread operator allows you to expand the contents of an iterable (like an object) into individual elements. This provides a concise syntax for object merging. **Pros and Cons:** * **Lodash.assign()**: * **Pro:** Reliable and well-tested within a comprehensive library. * **Con:** Adds an external dependency to your project (Lodash). * **Object.assign():** * **Pro:** Native JavaScript, no additional dependencies needed. Generally efficient. * **Con:** Can be less concise than the spread operator for simple merges. * **Spread Operator (`...`)**: * **Pro:** Very concise and readable syntax. Often performs well due to its native implementation. * **Con:** Might not handle complex object scenarios (like nested objects) as gracefully as `Object.assign()` or Lodash. **Other Considerations:** * **Specificity:** For simple object merging, the spread operator is often the most straightforward choice. * **Complexity:** If you're dealing with deeply nested objects or require more specialized merging behavior (e.g., handling circular references), `Object.assign()` or Lodash might be more suitable. **Alternatives:** While these are the common methods, other libraries like Immer and Ramda offer more specialized object merging strategies for specific use cases.
Related benchmarks:
lodash.assign vs object.assign vs spread
lodash assign vs spread
lodash assign vs object.assign vs spread operator - variable and constant
Spread Operator vs Lodash (v4.17.21)
Lodash.assign vs Object.assign vs spread assign
Comments
Confirm delete:
Do you really want to delete benchmark?