Advertisement
karlakmkj

Process module

Sep 30th, 2021
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let initialMemory = process.memoryUsage().heapUsed;
  2. let word = process.argv[2]; //the word that user typed begans at index 2
  3.  
  4. console.log(`Your word is ${word}`)
  5.  
  6. // Create a new array
  7. let wordArray = [];
  8.  
  9. // Loop 1000 times, pushing into the array each time
  10. for (let i = 0; i < 1000; i++){
  11.   wordArray.push(`${word} count: ${i}`)
  12. }
  13.  
  14. console.log(`Starting memory usage: ${initialMemory}. \nCurrent memory usage: ${process.memoryUsage().heapUsed}. \nAfter using the loop to add elements to the array, the process is using ${process.memoryUsage().heapUsed - initialMemory} more bytes of memory.`)
  15.  
  16. /*
  17. Type in the terminal then enter: node app.js apple  
  18. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement