Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash assign vs native
(version: 0)
Comparing performance of:
lodash vs native
Created:
4 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.min.js'></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo'};
Tests:
lodash
const copied = _.assign(person, {age: 15});
native
const copied = { ...person, age: 15 };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
18393870.0 Ops/sec
native
51822252.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmarking test cases for you. **What is being tested?** The main objective of this benchmark is to compare the performance of two approaches: using the `lodash` library and native JavaScript (i.e., without any external libraries) to assign a new property to an object. In the first test case, `_.assign(person, {age: 15})`, the `lodash` library's `assign` function is used to merge the `person` object with a new object containing the `age` property. The resulting object is assigned to a variable called `copied`. In the second test case, `{ ...person, age: 15 }`, an object spread operator (`...`) is used to create a shallow copy of the `person` object and add a new `age` property. This native JavaScript approach does not require any external libraries. **Options compared** The two options being compared are: 1. **Using `_lodash.assign()`**: This method uses the `assign` function from the `lodash` library to merge objects. 2. **Native JavaScript spread operator (`...`)**: This method uses the object spread operator to create a shallow copy of an object and add new properties. **Pros and cons of each approach** 1. **Using `_lodash.assign()`**: * Pros: Can handle complex merging scenarios, including recursive objects and arrays. * Cons: Requires an external library (in this case, `lodash`), which may introduce overhead due to loading times or file size. 2. **Native JavaScript spread operator (`...`)**: * Pros: Lightweight, does not require any external libraries, and is often faster since it's a built-in method. * Cons: Limited to shallow copying of objects; only works for simple assignments. **Library and its purpose** The `_lodash` library is a popular utility library for JavaScript that provides various functions for tasks such as string manipulation, array operations, and object manipulation. In this benchmark, the `assign` function from the library is used to merge two objects. **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in these benchmarks. However, note that some older browsers might not support the object spread operator (`...`). This benchmark assumes a modern JavaScript environment with support for this feature. **Other alternatives** If you were to implement a custom assignment function without using any external libraries, you could use various approaches, such as: * Using `Object.assign()` from the built-in `Object` prototype. * Creating a custom loop that iterates over the properties of the source object and adds them to the target object. However, these alternatives might not offer the same level of convenience or performance as using the object spread operator or a well-optimized library like `lodash`. I hope this explanation helps you understand what's being tested in this benchmark!
Related benchmarks:
Object.assign vs Lodash.assign
Object.assign vs Lodash.assign (4.17.21)
Lodash.assign vs Object.assign
Lodash.assign vs Object.assign vs spread assign
Comments
Confirm delete:
Do you really want to delete benchmark?