Skip to content

Instantly share code, notes, and snippets.

@isaacs isaacs/z.js
Created Jan 26, 2012

Embed
What would you like to do?
#!node --expose-gc
var zlib = require('zlib');
var buffer = new Buffer('eJzT0yMAAGTvBe8=', 'base64');
function nullfun(){
};
var cnt = process.argv[2] || 1e3;
cnt = +cnt
var c = cnt
//c = 2
// set here just to not treat the memoryUsage tracking
// as a leak itself.
var startMem = process.memoryUsage()
var didStartMem = false
function test() {
try { gc() } catch (e) {}
debugger
if (c -- <= 0) return end()
var u = process.memoryUsage()
if (!didStartMem) {
startMem = u
didStartMem = true
}
console.log(u, c);
var z = zlib.Unzip()
z.on("end", process.nextTick.bind(process, test))
// z.on("end", test)
z.end(buffer);
};
// process.nextTick(test);
test()
function end () {
console.error("ending...")
setTimeout(function () {
var endMem = process.memoryUsage()
console.error("start", startMem)
console.error("end ", endMem)
var diff = Object.keys(startMem).reduce(function (s, k) {
s[k] = endMem[k] - startMem[k]
return s
}, {})
console.error("diff ", diff)
var avgLeak = Object.keys(startMem).reduce(function (s, k) {
s[k] = diff[k] / cnt
return s
}, {})
console.error("leak ", avgLeak)
}, 500)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.