Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.