Skip to content

Instantly share code, notes, and snippets.

@oroce
Created May 12, 2013 15:08
Show Gist options
  • Save oroce/5563862 to your computer and use it in GitHub Desktop.
Save oroce/5563862 to your computer and use it in GitHub Desktop.
should test this on linux, on mac it's terrible.
var async = require( "async" );
var amount = 100*100*100;
var _arr = Array(amount).join(0).split(0);
var dummyFunction = function( cb ){
return setTimeout(cb, 2);
};
var runBind = function( fn ){
async.parallel(
_arr.map(function(){
return dummyFunction.bind( this );
}), fn
);
};
var runCall = function( fn ){
async.parallel(
_arr.map(function(){
return dummyFunction;
}), fn
);
};
var runAnonFunction = function( fn ){
async.parallel(
_arr.map(function(){
return function( cb ){
dummyFunction(cb);
};
}), fn
);
};
var target = process.argv[2];
var toRun;
switch( target ){
case "bind":
toRun = runBind;
break;
case "call":
toRun = runCall;
break;
case "anon":
toRun = runAnonFunction;
break;
default:
throw new Error( "Missing option" );
}
console.log( "start running:", process.memoryUsage().rss/(1024*1024) + " MB");
toRun(function(){
console.log( "end", process.memoryUsage().rss/(1024*1024) + " MB");
setTimeout(function(){
console.log( "after 1 min", process.memoryUsage().rss/(1024*1024) + " MB");
process.exit();
},1000*60*4);
});
node --trace-gc --max-old-space-size=8192 test.js call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment