Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object.create vs _.clone
(version: 0)
Comparing performance of:
_.clone vs object.create
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>
Script Preparation code:
var items = { a: { b: 'b', c: { d: 'd', }, }, b: { b: 'b', c: { d: 'd', }, }, c: { b: 'b', c: { d: 'd', }, }, d: { b: 'b', c: { d: 'd', }, }, e: { b: 'b', c: { d: 'd', }, }, }
Tests:
_.clone
var cope = _.clone(items);
object.create
var cope = Object.create(items);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.clone
object.create
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.clone
1734677.9 Ops/sec
object.create
41716576.0 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 Overview** The benchmark compares two approaches: `object.create` and `_`.clone` (using Lodash). Both methods are used to create a deep copy of an object. **What is being tested?** In this benchmark, the test cases create a complex object with multiple levels of nesting (`items`). The goal is to measure which approach creates a deeper copy of the original object. **Options compared** There are two options being compared: 1. `_.clone(items)`: This uses Lodash's `_` namespace, which provides a `clone` function for deep copying objects. 2. `Object.create(items)`: This uses the built-in `Object.create()` method to create a new object with the specified prototype (in this case, `items`). **Pros and Cons of each approach** 1. `_.clone(items)`: * Pros: + Faster execution time, as it's a built-in Lodash function. + Deeper copy of the original object, which is important if you need to ensure that all nested properties are copied correctly. * Cons: + Requires including an external library (Lodash), which might add overhead. 2. `Object.create(items)`: * Pros: + No external library dependency, making it a simpler and more lightweight solution. + Still creates a deep copy of the original object, as it uses the prototype chain to create a new object with all the same properties. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string formatting, and object creation. The `_` namespace includes various helper functions like `clone`, which is used in this benchmark. **Special JS feature/syntax** There are no special features or syntax being tested in this benchmark. Both approaches use standard JavaScript syntax to create the object and copy it. **Other alternatives** If you're interested in alternative approaches, here are a few more: 1. Using `JSON.parse(JSON.stringify(items))`: This creates a deep copy of the original object by parsing the JSON representation of the object as a string, which is then parsed back into an object. 2. Using a library like `deepcopy` or `obj-freeze`: These libraries provide functions specifically designed for creating deep copies of objects. Keep in mind that while these alternatives might be viable options, they may not be as efficient or straightforward to use as the `Object.create()` method or Lodash's `_` namespace.
Related benchmarks:
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign
Object cloning with Lodash clone vs ES6 object spread vs ES6 Object.assign vs Json
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign vs Clone
Object cloning with Lodash cloneDeep vs ES6 object spread vs JSON.stringify
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign vs structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?