• Another example of fibonacci:

    print(`Initial: ${JSON.stringify(process.memory())}`);
    function fibonacci(num) {
      print(`num ${num}: ${JSON.stringify(process.memory())}`);
      if (num <= 1) return 1;
    
      return fibonacci(num - 1) + fibonacci(num - 2);
    }
    print(`Before: ${JSON.stringify(process.memory())}`);
    fibonacci(5);
    print(`After: ${JSON.stringify(process.memory())}`);
    

    Result:

    Initial: {"free":2379,"usage":121,"total":2500,"h­istory":0}
    Before: {"free":2373,"usage":127,"total":2500,"h­istory":0}
    num 5: {"free":2366,"usage":134,"total":2500,"h­istory":0}
    num 4: {"free":2360,"usage":140,"total":2500,"h­istory":0}
    num 3: {"free":2354,"usage":146,"total":2500,"h­istory":0}
    num 2: {"free":2348,"usage":152,"total":2500,"h­istory":0}
    num 1: {"free":2342,"usage":158,"total":2500,"h­istory":0}
    num 0: {"free":2341,"usage":159,"total":2500,"h­istory":0}
    num 1: {"free":2347,"usage":153,"total":2500,"h­istory":0}
    num 2: {"free":2353,"usage":147,"total":2500,"h­istory":0}
    num 1: {"free":2347,"usage":153,"total":2500,"h­istory":0}
    num 0: {"free":2346,"usage":154,"total":2500,"h­istory":0}
    num 3: {"free":2359,"usage":141,"total":2500,"h­istory":0}
    num 2: {"free":2353,"usage":147,"total":2500,"h­istory":0}
    num 1: {"free":2347,"usage":153,"total":2500,"h­istory":0}
    num 0: {"free":2346,"usage":154,"total":2500,"h­istory":0}
    num 1: {"free":2352,"usage":148,"total":2500,"h­istory":0}
    After: {"free":2373,"usage":127,"total":2500,"h­istory":0}
    

    It's fun to see how the RAM usage grows, but I don't find how I can get the peak RAM usage of the program without putting process.memory() on every step...

About

Avatar for Ragtime @Ragtime started