Timeline for JavaScript "recursion" via setTimeout
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 1, 2013 at 16:42 | vote | accept | samfrances | ||
| Feb 1, 2013 at 16:32 | comment | added | Benjamin Gruenbaum | @samfrances Breaking out of deep calculation and splitting work through setTimeout is a known technique but it's not too effective any more. In new browsers you should use Web Workers for this sort of thing instead.Like dystroy said it doesn't make sense to try to do integer operations on numbers this big. | |
| Feb 1, 2013 at 15:58 | history | edited | Denys Séguret | CC BY-SA 3.0 |
edited body
|
| Feb 1, 2013 at 15:53 | comment | added | samfrances | I see. I was only using factorial composition as an example of a recursive function. I was trying to find a general tactic for carrying out recursive computations that might take a long time to complete without freezing the page. Factorial was just the first recursive function that came to mind (although once I noticed the bug in my example, I was keen to understand why it was there). | |
| Feb 1, 2013 at 15:49 | comment | added | Denys Séguret |
Your computation won't freeze the computer if you try to compute numbers smaller than 2^52 : factorial grows very fast. If you have long computations (which I hadn't thought was the problem), then yes you might use setTimeout or a webworker.
|
|
| Feb 1, 2013 at 15:46 | comment | added | samfrances | "using a recursion might be amusing solutions but they're not terribly effective". Even if the aim of the exercise is to prevent the interface freezing while a calculation completes (perhaps not applicable to this function, but can happen), rather than to compute the function as fast as possible? Or would it be better just to use a web worker? | |
| Feb 1, 2013 at 15:43 | history | edited | Denys Séguret | CC BY-SA 3.0 |
added 126 characters in body
|
| Feb 1, 2013 at 15:35 | history | answered | Denys Séguret | CC BY-SA 3.0 |