Test name | Executions per second |
---|---|
_cloneDeep | 43506.0 Ops/sec |
Object spread | 194373.7 Ops/sec |
Structured clone | 38711.9 Ops/sec |
Object.assign | 141444.1 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
window.obj = {};
// 10 number properties
for (let i = 0; i < 10; i++) {
const key = (Math.random() + 1).toString(36).substring(7);
obj[key] = Math.random();
}
// 10 nested object properties
for (let i = 0; i < 10; i++) {
const key = (Math.random() + 1).toString(36).substring(7);
obj[key] = {
foo: Math.random(),
bar: true,
baz: {
baz: "Hello World"
}
}
}
const obj2 = _.cloneDeep(obj)
const obj3 = {obj}
const obj4 = structuredClone(obj)
const obj5 = Object.assign({}, obj)