summaryrefslogtreecommitdiff
path: root/perf/memory.js
blob: 1edab207786e3f78a5219ccb622643f3129b7724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
});