Skip to content

Instantly share code, notes, and snippets.

@debonx
Created January 19, 2020 19:04
Show Gist options
  • Save debonx/0ad85daae9bfa7ce5b283817a08eb48a to your computer and use it in GitHub Desktop.
Save debonx/0ad85daae9bfa7ce5b283817a08eb48a to your computer and use it in GitHub Desktop.
Node: Accessing the process object.
let initialMemory = process.memoryUsage().heapUsed;
let word = process.argv[2];
console.log(`Your word is ${word}`)
// Create a new array
let wordArray = [];
// Loop 1000 times, pushing into the array each time
for (let i = 0; i < 1000; i++){
wordArray.push(`${word} count: ${i}`)
}
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.`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment