Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created June 5, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmactough/5769386f29905963a7c420c6afb870bc to your computer and use it in GitHub Desktop.
Save danmactough/5769386f29905963a7c420c6afb870bc to your computer and use it in GitHub Desktop.
var heapdump = require('heapdump');
var FeedParser = require('..');
var fs = require('fs');
var feed = __dirname + '/feeds/intertwingly.atom';
var ct = 10000;
global.gc();
var premem = process.memoryUsage().heapUsed;
if (process.env.HEAPDUMP) heapdump.writeSnapshot();
console.log("Pre: %s", premem);
function finishedRun () {
global.gc();
var postmem = process.memoryUsage().heapUsed;
var num = 10000 - ct + 1;
if (num % 100 === 0) {
if (process.env.HEAPDUMP) heapdump.writeSnapshot();
console.log("Run %s: %s", num, postmem);
}
if (--ct > 0) {
run(finishedRun);
}
else {
process.exit();
}
}
function run (cb) {
var feedparser = new FeedParser();
var input = fs.createReadStream(feed, {autoClose: true});
var output = fs.createWriteStream('/dev/null');
output.once('finish', cb);
input.pipe(feedparser);
function onReadable () {
var chunk;
while ((chunk = this.read()) !== null) {
output.write(JSON.stringify(chunk));
}
}
feedparser.on("readable", onReadable);
feedparser.once("end", function () {
feedparser.removeListener("readable", onReadable);
output.end();
});
}
run(finishedRun);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment