I have a simple recursive function to calculate the n
Fibonacci number, if for example, I call the function to find the number 40 this is called 331160281 times, and I guess it will consume a high volume of RAM (at least stack).
At the time of entering the memory inspector I do not see a remarkable consumption of RAM in the browsers.
My question is:
How do I know the amount of RAM memory (stack) that a script consumes javascript
?
If I'm wrong and it doesn't consume much RAM, then:
How can I see the battery consumed in time?
Example code:
function fibonacci(num){
count++;
if (num < 2) return num;
else return(fibonacci(num - 1) + fibonacci(num - 2));
}
var count=0;
document.write("El 40 número de Fibonacci es: "+fibonacci(40)+"<br>");
document.write("La funcion de Fibonacci se ha llamado "+count+" veces.<br>");
I answer myself.
The problem is that it doesn't really consume that much battery, the call path is tree-shaped, and when a branch ends, before continuing the next one, the function has already "returned", so it empties the stack.
So looking up the number 40 only stacks at most 41 calls (from f(40) to f(0) ), which would consume 328 Bytes on a 64-bit system.
It only occurs to me that you look at the RAM used by that tab in your browser, for example Google Chrome has a task manager very similar to Windows and I think it will help you a lot since it shows the memory and CPU used by the extensions or tabs of the browser.
To access this, it can be done by using the Shift + Escape key combination or, by default, from the menu button, access the More tools option and then select Task Manager .
Although it does not tell you how much your Script will consume, but it is a good tool to know how much your site consumes, it is very important to manage that due to mobiles.