Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
bench: run GC and dump stats if --expose-gc is set
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Apr 27, 2012
1 parent 7063575 commit 4e84dfa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions benchmark/http_simple_auto.js
Expand Up @@ -105,5 +105,24 @@ server.listen(port, function () {
cp.stderr.pipe(process.stderr);
cp.on('exit', function() {
server.close();
process.nextTick(dump_mm_stats);
});
});

function dump_mm_stats() {
if (typeof gc != 'function') return;

var before = process.memoryUsage();
for (var i = 0; i < 10; ++i) gc();
var after = process.memoryUsage();
setTimeout(print_stats, 250); // give GC time to settle

function print_stats() {
console.log('\nBEFORE / AFTER GC');
['rss', 'heapTotal', 'heapUsed'].forEach(function(key) {
var a = before[key] / (1024 * 1024);
var b = after[key] / (1024 * 1024);
console.log('%sM / %sM %s', a.toFixed(2), b.toFixed(2), key);
});
}
}

0 comments on commit 4e84dfa

Please sign in to comment.