<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}};
var obj2 = JSON.parse(JSON.stringify(obj));
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}};
var obj2 = _.clone(obj, true);
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}};
var obj2 = Object.assign({}, obj);
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}};
var obj2 = R.clone(obj, true);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
json stringify | |
lodash deep clone | |
Object.assign | |
Ramda clone |
Test name | Executions per second |
---|---|
json stringify | 286890.1 Ops/sec |
lodash deep clone | 910621.8 Ops/sec |
Object.assign | 825806.9 Ops/sec |
Ramda clone | 352255.1 Ops/sec |
Let's dive into the benchmark definition and test cases.
Benchmark Definition: The benchmark is called "deep clone JSON". This means we're testing different methods for creating a deep copy of a JavaScript object, which involves cloning all nested objects recursively.
Test Cases:
Other Alternatives:
While not tested in this specific benchmark, other alternatives for deep copying objects include:
Keep in mind that each method has its trade-offs, and the best choice depends on your specific use case and requirements.