POV-Ray : Newsgroups : povray.off-topic : A comparison : Re: A comparison Server Time
10 Oct 2024 23:19:18 EDT (-0400)
  Re: A comparison  
From: scott
Date: 19 Mar 2008 06:28:53
Message: <47e0f8f5$1@news.povray.org>
I added a couple of lines:

function sum(list)
>   var total = 0;
>   var position = list.start();
>   while (position != null)
>   {
>     total = total + position.get_value();
>     position = position.get_next();
>   }
return total
end

> Pretty much a verbatim match there.

OK, so for your "Other Method" we have:

function sum(list)
 if( list.start() == NULL )
   return 0
 else
   return list.get_value() + sum(list.get_next())
 endif
end

> And of course, accessing parts of a list requires splitting them, and 
> recusion isn't looping. ;-)

I suspect the recursion method is slower, because calling a function has 
some overheads (storing and recalling registers and return address on stack 
etc).


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.