Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
Firefox 68
Windows
Desktop
5 years ago
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
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
arrayOf1kkNumbers = new Array(1000000).fill(1).map((_,index) => index);
Tests:
  • 1. concat

     
    const clonedArr = [].concat(arrayOf1kkNumbers);
  • 2. spread

     
    const clonedArr = [...arrayOf1kkNumbers];
  • 3. slice

     
    const clonedArr = arrayOf1kkNumbers.slice();
  • 4. map

     
    const clonedArr = arrayOf1kkNumbers.map(i=>i);
  • 5. Object values

     
    const clonedArr = Object.values(arrayOf1kkNumbers);
  • 6. Array.from

     
    const clonedArr = Array.from(arrayOf1kkNumbers);
  • 7. JSON.stringify -> parse

     
    const clonedArr = JSON.parse(JSON.stringify(arrayOf1kkNumbers));
  • 8. lodash map

     
    const clonedArr = _.map(arrayOf1kkNumbers, i => i);
  • 9. lodash cloneDeep

     
    const clonedArr = _.cloneDeep(arrayOf1kkNumbers);
  • 10. lodash clone

     
    const clonedArr = _.clone(arrayOf1kkNumbers);
  • 11. lodash filter

     
    const clonedArr = _.filter(arrayOf1kkNumbers);
  • 12. for

    x
     
    const clonedArr = [];
    const length = arrayOf1kkNumbers.length
    for (let i = 0; i < length; i++) {
      clonedArr.push(arrayOf1kkNumbers[i]);
    }
  • 13. while

     
    const clonedArr = [];
    let i = 0;
    const length = arrayOf1kkNumbers.length
    while (i++ < length) {
      clonedArr.push(arrayOf1kkNumbers[i]);
    }
  • 14. filter

     
    const clonedArr = arrayOf1kkNumbers.filter(Boolean);
  • 15. reduce

     
    const clonedArr = arrayOf1kkNumbers.reduce((newArray, element) => {
      newArray.push(element);
      return newArray;
    }, []);
  • 16. Object.assign

     
    const clonedArr = Object.assign([], arrayOf1kkNumbers);