Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object Clone Lodash vs structuredClone
(version: 0)
Compare performence for cloning an object in JS between lodash.clone and structuredClone
Comparing performance of:
Lodash vs structuredClone
Created:
3 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 arr = new Array(100000000).fill(0);
Tests:
Lodash
_.clone(arr);
structuredClone
structuredClone(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
0.7 Ops/sec
structuredClone
0.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark measures the performance of two methods for cloning an object in JavaScript: `lodash.clone` and `structuredClone`. **Options Compared** Two options are compared: 1. **Lodash**: The `_.clone()` method from the Lodash library, which is a utility library that provides a wide range of functions for functional programming. 2. **Structured Clone**: The `structuredClone()` function, which is a native JavaScript function introduced in ECMAScript 2020 (ES2020) as part of the WebAssembly specification. It allows cloning objects without creating new objects or allocating memory. **Pros and Cons** Here are some pros and cons for each approach: * **Lodash**: Pros: + Wide range of features beyond object cloning + Easy to use and understand, especially for developers familiar with functional programming + Well-maintained and widely adopted library * Cons: * Adds unnecessary overhead due to the complexity of Lodash functions * May not be optimized for performance **Structured Clone** Pros: * Native implementation, which means it's more likely to be optimized for performance * Creates a new object without allocating memory, reducing garbage collection overhead * Supports cloning objects with complex references and cyclic dependencies Cons: * Introduced in ES2020, so not supported in older browsers or environments * May require additional setup or configuration, especially for developers unfamiliar with the function **Library and Syntax** The `structuredClone()` function is part of the ECMAScript standard, which means it's a native JavaScript function. It was introduced as part of the WebAssembly specification to provide a way to clone objects without creating new objects or allocating memory. There is no special syntax required to use the `structuredClone()` function. You can simply call it on an object, like this: ```javascript const obj = { foo: 'bar' }; const clonedObj = structuredClone(obj); ``` **Alternative Approaches** Other alternatives for cloning objects in JavaScript include: * **JSON.parse(JSON.stringify(obj))**: This method creates a new object by serializing the original object to JSON and then parsing it back into an object. While it's simple, it can be slower than the `structuredClone()` function. * **Object.assign()**: This method creates a new object by copying properties from the original object. It's faster than `JSON.parse(JSON.stringify(obj))` but still may not outperform `structuredClone()` for large objects. Keep in mind that these alternatives have different trade-offs and may not offer the same level of performance or functionality as the `structuredClone()` function.
Related benchmarks:
Lodash cloneDeep vs Lodash clone vs Array.slice() vs. Object.assign()
Lodash cloneDeep vs. Lodash clone vs. Array.slice() vs. Array.slice(0) vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign() vs Array.slice() vs Array.slice(0)
Comments
Confirm delete:
Do you really want to delete benchmark?