Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Stringification vs. cloneDeep vs. Custom Copy
(version: 0)
Comparing performance of:
Stringification Deep Copy vs _.cloneDeep vs Custom Copy
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
Stringification Deep Copy
let stringyCopy = JSON.parse(JSON.stringify({ "name": { "first": "Billy", "last": "Bob", "middle": "Taylor" }, "vehicles": [{ "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "and so forth": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "test": { "first": "Billy", "last": "Bob", "middle": "Taylor" } } }, { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "junk": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "so on": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123] } } }] }));
_.cloneDeep
let deepCopy = _.cloneDeep({ "name": { "first": "Billy", "last": "Bob", "middle": "Taylor" }, "vehicles": [{ "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "and so forth": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "test": { "first": "Billy", "last": "Bob", "middle": "Taylor" } } }, { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "junk": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "so on": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123] } } }] });
Custom Copy
function copy(value) { if (value === null || value === undefined) { return value; } // Array, just call copy on each entry, map returns a new array. if (Array.isArray(value)) { return value.map(copy); } // Create a new object and copy everything else if (typeof value === 'object') { return Object.keys(value).reduce((copied, key) => { copied[key] = copy(value[key]); return copied; }, {}); } else { // Otherwise it is a scalar anyways. return value; } } const customCopy = copy({ "name": { "first": "Billy", "last": "Bob", "middle": "Taylor" }, "vehicles": [{ "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "and so forth": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "test": { "first": "Billy", "last": "Bob", "middle": "Taylor" } } }, { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "junk": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123], "so on": { "id": "1", "brand": "Toyota", "make": "Camry", "year": 2020, "nested": [1,2,3,4,5], "other": ["abc", 123] } } }] });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Stringification Deep Copy
_.cloneDeep
Custom Copy
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):
The task appears to be analyzing benchmark results from two tests: `Stringification Deep Copy` and `_cloneDeep`. The output provides detailed information about each test, including the browser used, device platform, operating system, number of executions per second, and test name. To answer the question, I would need more context or a specific question related to these benchmark results. However, based on the provided data, here are some possible observations: 1. **Browser and Device Platform**: The majority of the tests were run on Firefox 107 using Windows as the operating system. 2. **Execution Speed**: The `Stringification Deep Copy` test outperformed both `Custom Copy` and `_cloneDeep` in terms of execution speed per second. 3. **Test Performance**: Although not directly comparable, the performance of `_cloneDeep` is surprisingly high, considering it's a built-in JavaScript function. Without a specific question or request related to these benchmark results, I will refrain from providing further analysis. If you have any particular questions or need help with interpreting these results, feel free to ask!
Related benchmarks:
Lodash cloneDeep vs clone vs spread
Lodash cloneDeep vs JSON Clone with Array
cloneDeep vs JSON stringify + parse (long arr)
lodash cloneDeep vs json.stringify
Object cloning with Lodash clone vs cloneDeep vs merge vs structuredClone vs JSON.parse(JSON.stringify(o))
Comments
Confirm delete:
Do you really want to delete benchmark?