[REBOL] Re: On ordinal and cardinal numbers...
From: larry:ecotope at: 9-Jul-2001 12:59
Hi all,
Oops, my bad. There was a stupid (and critical) typo in the recursive
version, in the function body it called the iterative version RING-SKIP
instead of itself, RING-SKIP2.
> The second uses recursion:
>
> ring-skip2: func [s [series!] n [integer!]] [
> if n = 0 [return s]
> either positive? n [
> if tail? s: next s [s: head s]
> ring-skip s n - 1
> ][
> s: back either head? s [tail s][s]
> ring-skip s n + 1
> ]
> ]
When corrected, the recursive version fails with a stack overflow at a skip
value of 1515. The timings where b is a block of 10000 integers and the skip
value is 1514 are:
>> t: now/time/precise loop 100 [ring-skip b 1514] now/time/precise - t
== 0:00:00.44
>> t: now/time/precise loop 100 [ring-skip2 b 1514] now/time/precise - t
== 0:00:02.14
So the iterative version is about 5 times faster for the maximum skip value
allowed by the recursive version.
BTW I get the same results as Mark with his recursion test, a maximum stack
depth of 3147.
Clearly, as Joel indicated, we should prefer the iterative version, if we
anticipate using it on very large series.
Sorry for the confusion.
-Larry