Re: Profiling, recursive func slower than imperative, normal?



Gabriel Genellina wrote:
En Wed, 16 Apr 2008 17:53:16 -0300, <s0suk3@xxxxxxxxx> escribió:

On Apr 16, 3:27 pm, Jean-Paul Calderone <exar...@xxxxxxxxxx> wrote:

Any function can be implemented without recursion, although it isn't
always easy or fun.

Really? I'm curious about that, I can't figure out how that would
work. Could give an example? Say, for example, the typical: walking
through the file system hierarchy (without using os.walk(), which uses
recursion anyway!).

Use a queue of pending directories to visit:

start with empty queue
queue.put(starting dir)
while queue is not empty:
dir = queue.get()
list names in dir
for each name:
if is subdirectory: queue.put(name)
else: process file
Hi,

In that case, I'm not sure you get any performance gain since the queue has basically the same role as the stack in the recursive version. A definitive answer calls for an actual test, though.

Anyway if you want to process the tree depth-first, the queue version falls in the "not fun" category.

Cheers,
RB
.



Relevant Pages

  • Re: re numbering my Netflix queue - help
    ... I have also put what the current rankings are by Netflix viewers. ... Nanny McPhee almost 4 stars ... I have others in my queue but they say "long wait" so I didn't list them ... I thought 'Fun With Dick and Jane' and 'Chicken Little' were both fun. ...
    (rec.arts.movies.current-films)
  • Re: Profiling, recursive func slower than imperative, normal?
    ... through the file system hierarchy, ... recursion anyway!). ... I'm not sure you get any performance gain since the queue ... falls in the "not fun" category. ...
    (comp.lang.python)
  • Re: AVStream: DMA & Process() QUEUEing
    ... > empty queue. ... "Indicates that processing should occur every time a data frame arrives into ... the process dispatch is only called ... when data arrives into a previously empty queue." ...
    (microsoft.public.development.device.drivers)
  • Re: Times/Ayres: Queue for the lift: ten minutes. One Caesar salad: $40. Is this fun? Guess
    ... >Queue for the lift: ten minutes. ... One Caesar salad: $40. ... Is this fun? ...
    (alt.vacation.las-vegas)
  • Re: C# equivalent of some SML code
    ... elements and the type of queue because they have members like: ... IQueue<ELT, QUEUE> as QUEUE ... Apparently you cannot put anything static in an interface. ... The fact is, your requirement that the _interface_ provide a "static value representing the polymorphic empty queue" just seems wrong to me, at least in a language like C#. ...
    (microsoft.public.dotnet.languages.csharp)