Re: How can I format an integer ?
Re: How can I format an integer ?
- Subject: Re: How can I format an integer ?
- From: Barry Wainwright <email@hidden>
- Date: Wed, 05 Nov 2008 06:43:28 +0000
On 4 Nov 2008, at 23:53, Jon Pugh wrote:
At 7:45 PM -0500 11/4/08, Deivy Marck Petrescu wrote:
Luther not to disagree with the above statement, indeed, recursion
is much more CPU intensive, but, as Philip wrote above, it is more
logical.
As for being faster, it is but not by much.
Using Smile's chrono function and computing up to 150! these are
the times
There are certain problems, like the classic Towers of Hanoi, which
are logically simpler using recursion, but the real reason to avoid
recursion where possible is memory useage. 150 is not a large
sample. When you start talking thousands and millions, that's where
you'll see real differences. Recursion takes up stack space, which
is limited and non-expandable on almost every operating system. In
fact, this is recursion's greatest strength, it stores intermediate
values on the stack for only the duration of the algorithm.
So, speed isn't the real problem, memory use is. In most cases, the
iterative (loop) method will use considerably less memory.
Jon
While I don't disagree in principle and I don't use recursion in many
places, this particular purpose will rarely recurse more than 3 or 4
times through the loop as it is intended for formatting integers,
rather than very long numbers.
Recursion in this particular case is safe enough.
--
Barry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden