Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
klona vs Lodash cloneDeep
(version: 0)
Comparing performance of: Lodash cloneDeep vs Json clone vs RFDC copy vs klona copy
Comparing performance of:
Lodash cloneDeep vs Klona
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script> <script src="https://unpkg.com/klona@2.0.4/json/index.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);
Klona
myCopy = klona(sampleObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Klona
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
41464.3 Ops/sec
Klona
207751.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Definition** The benchmark is designed to compare the performance of three cloning functions: 1. `cloneDeep` from Lodash 2. `copy` from React Fiber Data Structure Control (RFDC) 3. `klona` These functions are responsible for creating a deep copy of an object. **Script Preparation Code** The script preparation code defines a sample object `sampleObject`, which is used as the input for the cloning functions. ```javascript var sampleObject = [{...}]; ``` This object has nested objects and arrays, making it suitable for testing cloning functionality. **Html Preparation Code** The html preparation code includes two external JavaScript files: 1. Lodash: `https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js` 2. Klona: `https://unpkg.com/klona@2.0.4/json/index.js` These libraries provide the cloning functions to be tested. **Individual Test Cases** The benchmark includes two test cases: 1. **Lodash cloneDeep**: Clones the sample object using Lodash's `cloneDeep` function. ```javascript myCopy = _.cloneDeep(sampleObject); ``` 2. **Klona**: Clones the sample object using Klona's `copy` function. ```javascript myCopy = klona(sampleObject); ``` **What are the pros and cons of each approach?** 1. **Lodash cloneDeep** * Pros: + Well-tested and widely used library + Supports deep cloning with options for customizing behavior * Cons: + Larger binary size due to Lodash's overhead + May not be as optimized for performance as other libraries 2. **Klona** * Pros: + Smaller binary size compared to Lodash + Optimized for performance, using a custom implementation * Cons: + Less well-known and tested library + May require more setup or configuration 3. **RFDC copy** * Pros: + Optimized for React Fiber's specific use case + Small binary size due to React Fiber's compact implementation * Cons: + Limited use case compared to Lodash and Klona + May not be suitable for general-purpose deep cloning **Library analysis** 1. **Lodash** * Purpose: A comprehensive utility library providing various functions, including `cloneDeep`. * Used by many popular projects and applications. 2. **Klona** * Purpose: A lightweight library specifically designed for creating deep copies of objects. * Optimized for performance, making it suitable for resource-constrained environments. **Benchmark results** The latest benchmark result shows that Klona outperforms Lodash in terms of execution speed (`ExecutionsPerSecond`). However, the actual performance difference may vary depending on the specific use case and environment.
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Parse
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 Lodash cloneDeep vs JSON Clone : Dup
Comments
Confirm delete:
Do you really want to delete benchmark?