I have measured the speed of two sorts of Javascript trampolines, which in both cases turned out to be about two orders of magnitude slower than iterative code: http://glat.info/pub/tailopt-js/tailopt-js-appendices.xhtml (mutual recursion supported)
As for the setTimeout solution, yes it simplifies the treatment a lot, and looks to me quite elegant. But it still creates a new function each time, so I doubt the performance can be much different from that of the trampoline implementation. Plus... several browsers incur a minimum delay of about 10ms. Lastly, you may not have setTimeout at all in a non-browser engine. But please, no misunderstanding: I do also think that trampolines are the way to go..... at the JS engine level, not above. What I am proposing is an automatism to explore a functional way of doing things, *now*, with performance being taken care of. I appreciate clearly separating layers of abstraction in many functions, and hope that things will someday change at the engine level. Guillaume -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com