Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.assign vs Object.assign vs spread assign
(version: 0)
Measuring approaches performance
Comparing performance of:
Lodash Assing vs Native Assing vs spread
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.21/lodash.js"></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo'};
Tests:
Lodash Assing
_.assign({}, person);
Native Assing
Object.assign({}, person);
spread
a = {...person}
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash Assing
Native Assing
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/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash Assing
3015881.0 Ops/sec
Native Assing
4937886.5 Ops/sec
spread
5084315.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Overview** The benchmark, hosted on MeasureThat.net, measures the performance of three approaches for assigning properties to an object: Lodash's `_assign`, the native `Object.assign()` method, and the spread operator (`...`). **Test Cases** The benchmark consists of three test cases: 1. **Lodash Assing**: This test case uses Lodash's `_assign` function to assign properties to an empty object. ```javascript _.assign({}, person); ``` 2. **Native Assing**: This test case uses the native `Object.assign()` method to assign properties to an empty object. ```javascript Object.assign({}, person); ``` 3. **spread**: This test case uses the spread operator (`...`) to assign properties to an empty object. ```javascript a = {...person}; ``` **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers. In this benchmark, Lodash's `_assign` function is used to concatenate two or more objects into one. **Spread Operator (`...`)** The spread operator is a syntax sugar introduced in ECMAScript 2015 (ES6) for creating new arrays from iterable sources. When used with objects, the spread operator creates a new object by spreading the properties of an existing object into a new object. **Native `Object.assign()` Method** The native `Object.assign()` method was introduced in ECMAScript 2015 (ES6) and is used to assign own enumerable properties of source objects to target objects. This method is implemented in most modern JavaScript engines. **Options Compared** In this benchmark, the following options are compared: * **Lodash Assing**: Uses Lodash's `_assign` function. + Pros: Convenient and flexible way to concatenate objects. Wide range of utility functions available in Lodash. + Cons: Adds an external dependency (Lodash) and may introduce overhead due to its complexity. * **Native Assing**: Uses the native `Object.assign()` method. + Pros: Efficient and lightweight, as it's implemented in most JavaScript engines. + Cons: May have performance variations depending on the engine implementation. * **spread**: Uses the spread operator (`...`). + Pros: Simple and concise syntax. No external dependencies required. + Cons: Limited functionality compared to Lodash and native `Object.assign()`. **Other Considerations** When choosing an approach, consider the following factors: * Performance: If speed is critical, the native `Object.assign()` method or spread operator may be a better choice. * Convenience: If you need to perform multiple assignments or concatenations, Lodash's `_assign` function might be more convenient. * Dependency management: Be aware that using an external library like Lodash may introduce dependencies that need to be managed. **Alternatives** Other alternatives for assigning properties to objects include: * **Array.prototype.push()**: While not ideal for object assignments, `push()` can be used to assign properties to an array. However, this approach is less efficient and more prone to errors. * **Object.assign() with a spread operator**: This approach combines the benefits of native `Object.assign()` and the spread operator: `(a = {...b}).assign(c);` * **Library alternatives**: Other utility libraries like Underscore.js or Ramda can provide similar functionality to Lodash.
Related benchmarks:
Object.assign vs Lodash.assign
Object.assign vs Lodash.assign (4.17.21)
Lodash.assign vs Object.assign
Object.assign vs Lodash.omit
Comments
Confirm delete:
Do you really want to delete benchmark?