Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created May 17, 2011 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmpvar/976918 to your computer and use it in GitHub Desktop.
Save tmpvar/976918 to your computer and use it in GitHub Desktop.
var
Context = process.binding('evals').Context,
Script = process.binding('evals').Script,
total = 10000,
result = null;
process.nextTick(function memory() {
var mem = process.memoryUsage();
console.log('rss:', Math.round(((mem.rss/1024)/1024)) + "MB");
setTimeout(memory, 100);
});
console.log("STARTING");
process.nextTick(function run() {
var context = new Context(), timers = {
interval : [],
timeout : []
};
context.setInterval = function(fn, timeout) {
timers.interval.push(setInterval(fn, timeout));
},
context.setTimeout = function(fn, timeout) {
timers.timeout.push(setTimeout(fn, timeout));
};
Script.runInContext('setInterval(function() {}, 0);',
context, 'test.js');
process.nextTick(function() {
var intervalLength = timers.interval.length,
timeoutLength = timers.timeout.length;
while (intervalLength--) {
clearInterval(timers.interval[intervalLength]);
}
while (timeoutLength--) {
clearTimeout(timers.timeout[timeoutLength]);
}
context.stop();
});
total--;
if (total) {
process.nextTick(run);
} else {
console.log("COMPLETE");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment