Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. /**
  2. * Below functions are executed against array of random
  3. * numbers of length 10000000. i.e numArray, which has a
  4. * length of 10000000.
  5. */
  6. const processData = () => {
  7. const start = Date.now();
  8. numArray.map(num => num * 99).reduce((acc,num) => acc+num);
  9.  
  10. const timeTaken = Date.now() - start;
  11. console.log(timeTaken);
  12. }
  13.  
  14. const processDataInLoop = () => {
  15. const start = Date.now();
  16. let total = 0;
  17. for(let i=0; i< numArray.length; i++){
  18. total = total + numArray[i] * 99;
  19. }
  20.  
  21. const timeTaken = Date.now() - start;
  22. console.log(timeTaken);
  23. };
  24.  
  25. processData(); // 8229ms
  26. processDataInLoop(); // 16ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement