Skip to content

Instantly share code, notes, and snippets.

@JonDum
Created November 27, 2012 22:30
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 JonDum/4157610 to your computer and use it in GitHub Desktop.
Save JonDum/4157610 to your computer and use it in GitHub Desktop.
Anonymous function allocation benchmark
//usage
// node test.js --nouse-idle-notification -test1
// node test.js --nouse-idle-notification -test2
// then compare memory usage
var a = [];
function Test1()
{
return function()
{
a.push({a: 'b'});
}
}
function Test2()
{
a.push({a: 'b'});
}
var c = 1000000;
var arguments = process.argv.splice(2);
if(arguments.indexOf('-test1') > 0)
{
while(c--)
Test1()();
}
if(arguments.indexOf('-test2') > 0)
{
while(c--)
Test2();
}
console.log(process.memoryUsage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment