Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC vs. Object Assign
(version: 1)
Even though this isn't a fair comparison since we're not talking deep cloning, this is a benchmark to see if RFDC can be used in any case, deep cloning or not.
Comparing performance of:
RFDC Clone vs Object Assign
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rfdc@1.3.0/index.min.js"></script>
Script Preparation code:
var originalObj = { key: 12345, name: 'Original Object', isTrue: true }; var clonedObj = null;
Tests:
RFDC Clone
var clone = rfdc(); clonedObj = clone(originalObj);
Object Assign
clonedObj = Object.assign({}, originalObj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
RFDC Clone
Object Assign
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; rv:123.0) Gecko/20100101 Firefox/123.0
Browser/OS:
Firefox 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RFDC Clone
12853832.0 Ops/sec
Object Assign
50565388.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark definition provides two options for creating a cloned object: 1. **RFDC (Replacer for Deep Copy)**: This option uses the `rfdc()` function, which is a deep cloning library that creates a new object with references to all properties of the original object. 2. **Object Assign**: This option uses the `Object.assign()` method, which creates a shallow clone of an object by copying its own enumerable properties. **What is being tested?** The benchmark tests the performance difference between these two methods in creating a cloned object. The test case measures the execution speed of each approach. **Pros and Cons of each approach:** 1. **RFDC (Replacer for Deep Copy)**: * Pros: + Provides a deep clone, which is useful when working with complex objects that contain other objects. + Can be more efficient than shallow cloning if the original object has many nested properties. * Cons: + Can be slower than shallow cloning due to the overhead of creating new objects and recursively copying properties. 2. **Object Assign**: * Pros: + Faster execution speed compared to deep cloning, especially for shallow clones. + More widely supported and used in JavaScript applications. * Cons: + Creates a shallow clone, which may not be suitable for complex objects with nested properties. **Library usage** The `rfdc` library is used in the benchmark. This library provides a simple way to create deep clones of objects by returning an array of replacers that can then be applied to the original object. **Special JavaScript feature or syntax** None mentioned. **Other alternatives** If you need to perform cloning operations, other alternatives include: * Lodash's `cloneDeep` function * JSON.parse(JSON.stringify(obj)) (a simple way to create a deep clone, but may not work as expected with some objects) * Recursion-based cloning using a custom function It's worth noting that the best approach depends on the specific use case and requirements. If you need to work with complex objects and don't mind slower execution speed, RFDC might be a better choice. For simpler clones or when performance is critical, Object Assign could be a more suitable option.
Related benchmarks:
Object.assign mutation vs spread
JS Cloning benchmarking
Object.assign vs mutation
Lodash clone deep object array vs string array
Comments
Confirm delete:
Do you really want to delete benchmark?