Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs native Clone
(version: 1)
Comparing performance of:
lodash clone vs native clone
Created:
8 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
Script Preparation code:
var obj = { "_id": "5a70cbe42440f696758f051f", "index": 0, "guid": "020c210f-6943-4e93-9335-822c5f9c72fc", "isActive": false, "balance": "$2,608.00", "picture": "http://placehold.it/32x32", "age": 21, "eyeColor": "brown", "name": "Slater Hodge", "gender": "male", "company": "ZORK", "email": "slaterhodge@zork.com", "phone": "+1 (905) 499-2902", "address": "115 Nova Court, Collins, Delaware, 710", "about": "Ea laborum esse nostrud do excepteur incididunt. Duis dolor fugiat qui sint occaecat occaecat adipisicing amet reprehenderit cupidatat qui do. Exercitation ullamco sint enim pariatur quis duis. Commodo aliqua velit ut laborum velit incididunt veniam est. Culpa officia eu sit duis nostrud deserunt fugiat esse laboris tempor esse consectetur Lorem ipsum.\r\n", "registered": "2017-09-22T05:08:56 +07:00", "latitude": 50.226282, "longitude": -108.795712, "tags": [ "labore", "qui", "tempor", "officia", "ad", "laborum", "velit" ], "friends": [ { "id": 0, "name": "Carlene Lewis" }, { "id": 1, "name": "Esther Camacho" }, { "id": 2, "name": "Dillon Lancaster" } ], "greeting": "Hello, Slater Hodge! You have 2 unread messages.", "favoriteFruit": "banana" };
Tests:
lodash clone
var lodashClone = _.clone(obj);
native clone
var nativeClone = {...obj};
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash clone
native clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 129 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash clone
102763.1 Ops/sec
native clone
2873856.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition Overview** The benchmark measures the performance difference between two approaches: 1. **Native Clone**: Creating a new object by using the spread operator (`{...obj}`) or Object.assign(), which creates a shallow copy of the original object. 2. **Lodash Clone**: Using the `clone` function from the Lodash library to create a deep clone of the original object. **What is being tested?** The benchmark tests the performance difference between these two approaches: * Creating a new object using the spread operator or Object.assign() (native clone) * Using the Lodash `clone` function to create a deep clone of the original object **Options Compared** The benchmark compares the following options: 1. **Native Clone**: A simple and efficient way to create a shallow copy of an object using the spread operator or Object.assign(). 2. **Lodash Clone**: A more complex approach that creates a deep clone of an object, which can be useful for objects with nested structures. **Pros and Cons** * **Native Clone**: Pros: + Fast and efficient + Simple to implement + Shallow copy, which may not be suitable for all use cases (e.g., when dealing with complex data structures) * **Lodash Clone**: Pros: + Creates a deep clone of the object, which can be useful for objects with nested structures + Can handle complex data structures and edge cases + May be slower than native clone due to the overhead of the Lodash library Cons: * **Lodash Clone**: May introduce additional overhead due to the use of an external library. * **Native Clone**: May not be suitable for all use cases, especially those that require a deep copy. **Library: Lodash** The `clone` function from Lodash is used to create a deep clone of the original object. Lodash is a popular JavaScript utility library that provides a range of functions for tasks such as array manipulation, string manipulation, and more. **Special JS Features or Syntax** There are no special JS features or syntax used in this benchmark. **Alternative Approaches** Other approaches to creating clones of objects include: 1. **JSON.parse(JSON.stringify(obj))**: This method creates a deep clone of an object by serializing it as JSON and then parsing the result back into an object. 2. **For...in loop**: Creating a new object using a for...in loop, which iterates over the properties of the original object and assigns each property to a new object. 3. **Object.assign() with Object.create()**: This approach creates a new object by creating a new object instance using `Object.create()` and then assigning properties from the original object using `Object.assign()`. These alternative approaches may have different performance characteristics compared to the native clone and Lodash clone approaches tested in this benchmark.
Related benchmarks:
Lodash cloneDeep vs JSON Clone (Large Object 2)
hasVshasOwnProperty
lodash merge vs object.assign vs spread with larger data and no mutation
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Comments
Confirm delete:
Do you really want to delete benchmark?