diff options
author | Alexander Early <aearly@fluid.com> | 2015-06-08 00:02:47 -0700 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2015-06-08 00:02:47 -0700 |
commit | e91ff727d083df7556e3106b9416d617aa467cf4 (patch) | |
tree | 101c3fdeb75a55e6f9594a540f5a1088179d40b1 /perf | |
parent | b66e85d1cca8c8056313253f22d18f571e7001d2 (diff) | |
download | async-e91ff727d083df7556e3106b9416d617aa467cf4.tar.gz |
added memory benchmark from #552
Diffstat (limited to 'perf')
-rw-r--r-- | perf/memory.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/perf/memory.js b/perf/memory.js new file mode 100644 index 0000000..b2eaebb --- /dev/null +++ b/perf/memory.js @@ -0,0 +1,46 @@ +if (process.execArgv[0] !== "--expose-gc") { + console.error("please run with node --expose-gc"); + process.exit(1); +} + +var async = require("../"); +global.gc(); +var startMem = process.memoryUsage().heapUsed; + +function waterfallTest(cb) { + var functions = []; + + for(var i = 0; i < 10000; i++) { + functions.push(function leaky(next) { + function func1(cb) {return cb(); } + + function func2(callback) { + if (true) { + callback(); + //return next(); // Should be callback here. + } + } + + function func3(cb) {return cb(); } + + async.waterfall([ + func1, + func2, + func3 + ], next); + }); + } + + async.parallel(functions, cb); +} + +function reportMemory() { + global.gc(); + var increase = process.memoryUsage().heapUsed - startMem; + console.log("memory increase: " + + (+(increase / 1024).toPrecision(3)) + "kB"); +} + +waterfallTest(function () { + setTimeout(reportMemory, 0); +}); |