Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs Lodash cloneDeep vs JSON Clone : Dup
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs RFDC copy vs RFDC without circles
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/lodash@4.17.20/lodash.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:
Lodash cloneDeep
myCopy = _.cloneDeep(sampleObject);
Json clone
myCopy = JSON.parse(JSON.stringify(sampleObject));
RFDC copy
var clone = rfdc(); myCopy = clone(sampleObject);
RFDC without circles
var cloned = rfdc({ proto: true, circles: false }); myCopy = cloned(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
RFDC copy
RFDC without circles
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark. The provided JSON represents a set of JavaScript microbenchmarks testing the performance of three different libraries: Lodash, RFDC (a custom implementation), and a built-in JSON clone function. **Benchmark Definition** Each test case has a unique "Benchmark Definition" string that defines how to create a copy of the input `sampleObject`. Let's break them down: 1. **Lodash cloneDeep**: `myCopy = _.cloneDeep(sampleObject);` * The Lodash library provides a `cloneDeep` function that creates a deep copy of an object, including nested objects and arrays. * Pros: Efficiently handles complex data structures with multiple levels of nesting. * Cons: May consume more memory due to the deep cloning process. 2. **JSON Clone**: `myCopy = JSON.parse(JSON.stringify(sampleObject));` * The built-in `JSON` object provides a `parse` function that parses a JSON string into a JavaScript object, and a `stringify` function that converts a JavaScript object into a JSON string. * Pros: Fast and lightweight, as it only creates a shallow copy of the object. * Cons: May not work correctly for complex data structures with nested objects or arrays. 3. **RFDC copy**: `var clone = rfdc(); myCopy = clone(sampleObject);` * RFDC (a custom implementation) provides a `copy` function that creates a new instance of an object, including all its properties and methods. * Pros: Efficiently handles complex data structures with multiple levels of nesting, similar to Lodash. * Cons: Not as widely used or maintained as Lodash. **Individual Test Cases** Each test case has a unique "Test Name" that describes the specific benchmark being run. The results are displayed in the "RawUAString", which represents the raw user agent string of each browser execution, along with other metrics like `ExecutionsPerSecond`. The latest benchmark result shows that: * **RFDC without circles** (clone created with `rfdc({ proto: true, circles: false })`) is the fastest, with an average of 253861.5 executions per second. * **RFDC copy** (clone created with `rfdc()` ) comes in second, with an average of 252546.6875 executions per second. * **JSON Clone** is the slowest, with an average of 90672.546875 executions per second. * **Lodash cloneDeep** takes third place, with an average of 53584.0078125 executions per second. In summary, the results suggest that RFDC's custom implementation is the fastest way to create a copy of the input object, followed closely by Lodash's `cloneDeep` function. The built-in JSON clone function performs poorly due to its shallow copying nature and lack of support for complex data structures.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Clone
RFDC clone vs Lodash clone vs JSON Clone
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
RFDC clone (circles: true) vs Lodash cloneDeep vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?