Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Below functions are executed against array of random
- * numbers of length 10000000. i.e numArray, which has a
- * length of 10000000.
- */
- const processData = () => {
- const start = Date.now();
- numArray.map(num => num * 99).reduce((acc,num) => acc+num);
- const timeTaken = Date.now() - start;
- console.log(timeTaken);
- }
- const processDataInLoop = () => {
- const start = Date.now();
- let total = 0;
- for(let i=0; i< numArray.length; i++){
- total = total + numArray[i] * 99;
- }
- const timeTaken = Date.now() - start;
- console.log(timeTaken);
- };
- processData(); // 8229ms
- processDataInLoop(); // 16ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement