Alexander Burger <a...@software-lab.de> writes:

Hi Alex,

>> since I just wrote a little Wiki article about recursion in PicoLisp, I
>> would be curious about how recursion performs in comparison to iteration
>> in PicoLisp.
>
> OK, let's try. If I run this:
>
>    # Recursive
>    (bench
>       (do 1000000
>          (let (N 100)
>             (recur (N)
>                (if (=0 N)
>                   1
>                   (* N (recurse (dec N))) ) ) ) ) )
>
>    # Iterative
>    (bench 
>       (do 1000000
>          (let N 1
>             (for I 100
>                (setq N (* I N)) )
>             N ) ) )
>
>    # Simple
>    (bench 
>       (do 1000000
>          (apply * (range 1 100)) ) )
>
> then I get:
>
>    13.161 sec
>    7.331 sec
>    7.413 sec
>    -> 
> 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
>
> So the recursive version takes about twice as long as the other two.

Thanks, nice to know. I find that interesting enough that I would like
to add it to the 'Recursion' Wiki article - what do you think?

-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to