Test name | Executions per second |
---|---|
1. concat | 94.3 Ops/sec |
2. spread | 60.2 Ops/sec |
3. slice | 238.9 Ops/sec |
4. map | 100.8 Ops/sec |
5. Object values | 81.7 Ops/sec |
6. Array.from | 49.9 Ops/sec |
7. JSON.stringify -> parse | 8.6 Ops/sec |
8. lodash map | 72.7 Ops/sec |
9. lodash cloneDeep | 8.7 Ops/sec |
10. lodash clone | 96.1 Ops/sec |
11. lodash filter | 72.4 Ops/sec |
12. for | 59.4 Ops/sec |
13. while | 56.3 Ops/sec |
14. filter | 104.6 Ops/sec |
15. reduce | 65.5 Ops/sec |
16. Object.assign | 5.9 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
arrayOf1kkNumbers = new Array(1000000).fill(1).map((_,index) => index);
const clonedArr = [].concat(arrayOf1kkNumbers);
const clonedArr = [arrayOf1kkNumbers];
const clonedArr = arrayOf1kkNumbers.slice();
const clonedArr = arrayOf1kkNumbers.map(i=>i);
const clonedArr = Object.values(arrayOf1kkNumbers);
const clonedArr = Array.from(arrayOf1kkNumbers);
const clonedArr = JSON.parse(JSON.stringify(arrayOf1kkNumbers));
const clonedArr = _.map(arrayOf1kkNumbers, i => i);
const clonedArr = _.cloneDeep(arrayOf1kkNumbers);
const clonedArr = _.clone(arrayOf1kkNumbers);
const clonedArr = _.filter(arrayOf1kkNumbers);
const clonedArr = [];
const length = arrayOf1kkNumbers.length
for (let i = 0; i < length; i++) {
clonedArr.push(arrayOf1kkNumbers[i]);
}
const clonedArr = [];
let i = 0;
const length = arrayOf1kkNumbers.length
while (i++ < length) {
clonedArr.push(arrayOf1kkNumbers[i]);
}
const clonedArr = arrayOf1kkNumbers.filter(Boolean);
const clonedArr = arrayOf1kkNumbers.reduce((newArray, element) => {
newArray.push(element);
return newArray;
}, []);
const clonedArr = Object.assign([], arrayOf1kkNumbers);