Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Clone
(version: 0)
Comparing performance of:
RFDC copy vs Clone
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rfdc@1.1.4/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/clone@2.1.2/clone.min.js"></script>
Script Preparation code:
var sampleObject = [{ "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil's Food" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5007", "type": "Powdered Sugar" }, { "id": "5006", "type": "Chocolate with Sprinkles" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0002", "type": "donut", "name": "Raised", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0003", "type": "donut", "name": "Old Fashioned", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] } ]; var myCopy = null;
Tests:
RFDC copy
var clone = rfdc(); myCopy = clone(sampleObject);
Clone
myCopy = clone(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
RFDC copy
Clone
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
RFDC copy
243260.3 Ops/sec
Clone
51305.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of microbenchmarks and explore what's happening in this particular benchmark. **Benchmark Definition** The benchmark is designed to compare the performance of two approaches: **RFDC (Recursive Function Call Delegation)** and simple copying. The input data consists of an array of objects, each representing a "donut" with various properties such as `id`, `type`, `name`, `ppu`, `batters`, and `topping`. **Script Preparation Code** The preparation code creates a sample object and assigns it to the variable `sampleObject`. The `var myCopy = null;` line is intentionally set to `null` to test how each approach handles this situation. **Html Preparation Code** The HTML code includes two external script files: 1. `rfdc@1.1.4/index.min.js`: This is the implementation of the RFDC algorithm, which is a technique for efficiently cloning objects in JavaScript. 2. `clone@2.1.2/clone.min.js`: This is a simple copying library that provides a basic way to clone objects. **Individual Test Cases** There are two test cases: 1. **RFDC copy**: This test case uses the RFDC algorithm to create a copy of the `sampleObject` array. ```javascript var clone = rfdc(); myCopy = clone(sampleObject); ``` 2. **Clone**: This test case simply assigns the original `sampleObject` array to the variable `myCopy`. ```javascript myCopy = sampleObject; ``` **What's being tested?** The benchmark is testing the performance of each approach (RFDC and simple copying) when: * Creating a copy of an array with multiple levels of nested objects (e.g., `batters` and `topping` arrays). * Assigning a null value to a variable after cloning or copying. **Pros and Cons** **RFDC approach:** Pros: * Can handle complex object structures more efficiently than simple copying. * May be faster for large datasets due to its optimization techniques. Cons: * Requires the RFDC library, which adds an overhead. * May have performance issues with very large objects or deep nesting. Simple copying (using `clone` library): Pros: * Simple and easy to understand. * Does not require any additional libraries. * Should be faster for small datasets or simple object structures. Cons: * Can be slower than RFDC for complex object structures. * May not handle very large objects or deep nesting efficiently. **Other considerations** When interpreting the benchmark results, keep in mind that: * The `ExecutionsPerSecond` value represents the average number of executions per second on a specific browser and device configuration. * The actual performance difference between RFDC and simple copying may vary depending on the specific use case and requirements. **Alternatives** If you're interested in exploring other alternatives, here are a few options: * `JSON.parse(JSON.stringify(obj))`: This method creates a deep copy of an object by serializing it to JSON and then parsing it back. * `Array.prototype.slice()`: This method creates a shallow copy of an array by copying its elements into a new array. * `lodash.cloneDeep()`: This is another popular library for creating deep copies of objects. Note that each approach has its own strengths and weaknesses, and the best choice depends on your specific requirements and performance considerations.
Related benchmarks:
RFDC clone vs Lodash clone vs JSON Clone
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structured clone
RFDC clone vs Clone vs JSON Clone
JSON Clone vs Clone
Comments
Confirm delete:
Do you really want to delete benchmark?