Created
June 30, 2011 03:39
-
-
Save justmoon/1055587 to your computer and use it in GitHub Desktop.
node-binary/node-chainsaw memory leak demo
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
var profiler = require('v8-profiler'); | |
var Binary = require('binary'); | |
var EventEmitter = require('events').EventEmitter; | |
var em = new EventEmitter; | |
var CHAIN_LENGTH = 5000; | |
var benchmarkTimer; | |
Binary.stream(em) | |
.loop(function (end) { | |
var vars_ = this.vars; | |
this | |
.scan('filler', 'BEGINMSG') | |
.buffer('cmd', 3) | |
.word8('num') | |
.tap(function (vars) { | |
if (vars.cmd.toString('ascii') == 'end') end(); | |
}) | |
; | |
}) | |
.tap(function (vars) { | |
var duration = (new Date).getTime() - benchmarkTimer; | |
var memory = process.memoryUsage(); | |
//profiler.stopProfiling('genChain'); | |
profiler.takeSnapshot('finalHeap'); | |
console.log("Downloaded "+CHAIN_LENGTH+" blocks in " + duration + "ms"); | |
console.log("Memory usage: "+memory.vsize); | |
debugger; | |
}) | |
; | |
process.nextTick(function () { | |
benchmarkTimer = (new Date).getTime(); | |
for (var i = 0; i < CHAIN_LENGTH; i++) { | |
em.emit('data', new Buffer("BEGINMSGcmd\x01" + | |
"GARBAGEDATAXXXX" + | |
"BEGINMSGcmd\x02" + | |
"BEGINMSGcmd\x03", 'ascii')); | |
} | |
em.emit('data', new Buffer("BEGINMSGend\x03", 'ascii')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment