Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash-deepClone_vs_native-parse-stringify
(version: 0)
Comparing performance of:
lodash-deepClone vs native-parse-stringify
Created:
6 years ago
by:
Registered User
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>
Script Preparation code:
window.source = { "pres_verbatim": { "inputName": "pres_verbatim", "displayName": "presence verbatim", "values": [{ "key": "Oui", "doc_count": 6876 }] }, "q1nve-satisfaction-globale": { "inputName": "Q1_NVE - satisfaction globale", "displayName": "Q1_NVE - satisfaction globale", "values": [{ "key": "Très satisfait", "doc_count": 3025 }, { "key": "Satisfait", "doc_count": 2063 }, { "key": "Peu satisfait", "doc_count": 946 }, { "key": "Pas du tout satisfait", "doc_count": 842 }] }, "q27nve-satisfaction-de-la-ponctualite-du-technicien": { "inputName": "Q27_NVE - satisfaction de la ponctualité du technicien", "displayName": "Q27_NVE - satisfaction de la ponctualité du technicien", "values": [{ "key": "Très satisfait", "doc_count": 3571 }, { "key": "Satisfait", "doc_count": 1273 }, { "key": "", "doc_count": 1244 }, { "key": "Pas du tout satisfait", "doc_count": 418 }, { "key": "Peu satisfait", "doc_count": 370 }] } };
Tests:
lodash-deepClone
let clone = _.cloneDeep(source);
native-parse-stringify
let clone = JSON.parse(JSON.stringify(source));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash-deepClone
native-parse-stringify
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):
I'd be happy to explain the benchmark and its results. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: using Lodash's `deepClone` function to clone an object, and using native JSON stringification and parsing to achieve the same result. The test data consists of a JSON object with several nested levels, which represents real-world data. **Benchmark Definition Json** The provided JSON defines two benchmark definitions: 1. `lodash-deepClone`: This benchmark definition uses Lodash's `deepClone` function to clone the input JSON object. ```javascript let clone = _.cloneDeep(source); ``` 2. `native-parse-stringify`: This benchmark definition uses native JavaScript methods to create a deep copy of the input JSON object by stringifying and parsing it again. ```javascript let clone = JSON.parse(JSON.stringify(source)); ``` **Options Compared** The two approaches differ in how they handle nested objects: 1. `lodash-deepClone`: * Uses Lodash's internal implementation, which recursively clones all nested objects and arrays. * Preserves the original data structure and relationships between objects. 2. `native-parse-stringify`: * Creates a deep copy of the input object by serializing it to a JSON string using `JSON.stringify()`. * Parses the resulting string back into a JavaScript object using `JSON.parse()`. **Pros and Cons** Here are some pros and cons for each approach: **Lodash's `deepClone`** Pros: * Preserves the original data structure and relationships between objects. * Can handle complex, deeply nested data structures. Cons: * Requires Lodash to be included in the benchmarking environment. * May have overhead due to Lodash's internal implementation. **Native `JSON.parse()` and `JSON.stringify()`** Pros: * Does not require any additional libraries or dependencies. * Uses native JavaScript methods, which can be faster than relying on a library like Lodash. Cons: * Can lose metadata and relationships between objects during the cloning process. * May not handle complex data structures as efficiently as `deepClone`. **Other Considerations** In addition to these two approaches, other alternatives for deep cloning in JavaScript include: 1. Using `Array.prototype.slice()` or `Object.assign()`: These methods can be used to create shallow copies of arrays and objects, but may not work correctly for deeply nested data structures. 2. Implementing a custom deep cloning function using recursive iteration: This approach can be more efficient than relying on a library like Lodash, but requires manual implementation and testing. **Test Case Libraries** The test cases use the following libraries: 1. `lodash.js`: Used by the `lodash-deepClone` benchmark definition. 2. No additional libraries are required for the `native-parse-stringify` benchmark definition. **Special JS Features or Syntax** There are no special JavaScript features or syntax used in this benchmark. The focus is on comparing two different approaches to deep cloning, without relying on any advanced or experimental features.
Related benchmarks:
Lodash merge vs simple
Lodash cloneDeep vs structuredClone vs stringify/parse with large object 2
structuredClone test with large data
structuredClone test with large data v2
Comments
Confirm delete:
Do you really want to delete benchmark?