Skip to content

Instantly share code, notes, and snippets.

@longouyang
Created January 21, 2016 23:33
Show Gist options
  • Save longouyang/c3d658e007271188218d to your computer and use it in GitHub Desktop.
Save longouyang/c3d658e007271188218d to your computer and use it in GitHub Desktop.
var n = 15000;
// Switching from repeat to map(fn, _.range(n)) causes this to use lots of
// memory. (~1GB)
// Setting n = 20000 gives "Allocation failed - process out of memory". Up the
// limit with e.g. node --max-old-space-size=2000
var data = repeat(n, function(i) {
var obj = {
name: uniformDraw(['foo', 'bar', 'baz']),
value: randomInteger(100)
}
// if (i % 500 === 0) {
// display(process.memoryUsage().rss / Math.pow(1024, 3));
// }
return obj
});
map(function(i) {
var d = data.slice(0, i * 1000);
var start = Date.now();
map(function(obj) { return d.name === 'foo'; }, d);
var end = Date.now();
//console.timeEnd('filter ' + i + 'k');
//display((process.memoryUsage().rss / Math.pow(1024, 3)) + ' GB');
console.log([i + 'k',
end - start,
process.memoryUsage().rss / Math.pow(1024, 3)].join(','))
//return
}, _.range(n / 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment