Created
June 5, 2016 14:26
-
-
Save danmactough/5769386f29905963a7c420c6afb870bc to your computer and use it in GitHub Desktop.
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 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