Created
September 1, 2019 13:14
-
-
Save amitzur/daadfdf280c2d893ac58a8009b28154b to your computer and use it in GitHub Desktop.
memory usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toMB = require('./toMB') | |
console.log(`[0]\t${takeMem()}`) | |
const MB = 1024 * 1024; | |
const MAX = MB * 200; | |
let s = '', i = -1; | |
const buff = Buffer.alloc(MAX); | |
const start = Date.now(); | |
while (++i < MAX) { | |
// s += 'a'; | |
buff.write('a', i) | |
// if (s.length === 1000000) console.log(s.length) | |
if (!(i % MB)) { | |
console.log(`[${toMB(i)}]\t${takeMem()}`) | |
} | |
} | |
const end = Date.now() | |
console.log(`${(end - start) / 1000} ms, ${toMB(buff.toString().length)}`); | |
function takeMem() { | |
const used = process.memoryUsage(); | |
return Object.keys(used).map(key => `${key} ${toMB(used[key])}`).join('\n\t') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment