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:
7 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
llama3.1:latest
, generated one year ago):
Let's dive into the world of JavaScript benchmarking. **What is being tested?** The provided JSON represents a benchmark test that compares three different approaches to assigning properties from one object to another: 1. **Lodash assign**: Using the `_assign` function from the Lodash library (a popular utility library for functional programming in JavaScript). 2. **Object.assign**: The built-in `Object.assign` method, which is a part of the ECMAScript 2015 (ES6) standard. 3. **Spread operator**: Using the spread syntax (`{ ...object1, ...object2 }`) to create a new object with properties from both objects. **What options are compared?** The three test cases compare different ways to assign properties from one object (`b`) to another (`a`): * In each case, `a` and `b` are initialized as objects: `var a = { a: 'oh', b: 'my' };\n var b = { c: 'goddess' };`. * The test cases then assign properties from `b` to `a`, using: + Lodash's `_assign` function (`var c = _.assign(a, b);`) + The built-in `Object.assign` method (`var c = Object.assign(a, b);`) + The spread operator syntax (`var c = { ...a, ...b };`) **Pros and Cons of each approach:** 1. **Lodash assign**: Pros: * Easy to use and understand. * Works across different browsers and versions (including older ones). * Well-documented in the Lodash library. Cons: - Requires including an additional library (Lodash) in your project. 2. **Object.assign**: Pros: * A built-in method, so no extra library is needed. * Part of the ES6 standard, so widely supported. * Performs well for most use cases. Cons: - May have performance issues with very large objects or complex nesting (as seen in this benchmark). 3. **Spread operator**: Pros: + A concise and expressive syntax. + Works well with modern JavaScript environments. + No additional library needed. Cons: - May not be as performant as `Object.assign` for large datasets. **Other considerations:** * The spread operator (`{ ...a, ...b }`) is a newer feature in JavaScript (introduced in ES6) and may not work correctly in older browsers or environments. * Lodash's `_assign` function provides more advanced features (like merging objects with arrays), which might be useful depending on your use case. **What library is used?** The `lodash` library is a popular utility library for functional programming in JavaScript. It provides various functions, including the `_assign` method, to make working with data structures easier and more efficient. That's it!
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?