From: Timothy Tin-Wai Chan
Subject: Speed of DOLIST vs. MAP... (was: Mapping is beautiful)
Date: 
Message-ID: <67@san-jacinto.cs.utexas.edu>
     Since someone mentioned about mapping, I want to take this
opportunity to ask a question I've always wanted an answer for:

          Which CL function runs faster, DOLIST or MAP...?

(I'm doing quite a big CL program that loops extensively and I'd like to
 speed up my program.  I'm not sure if I should use DOLIST or MAP...
 in situations when I can use either.)

-- 
----------------------------------------------------------------------
"Greater love has no man known, than a man lay his life down for his
 friends." (John 15:13)                               --- . ____
-- Timothy Chan (·······@ccwf.cc.utexas.edu)          /  / / / /

From: Michael Greenwald
Subject: Re: Speed of DOLIST vs. MAP... (was: Mapping is beautiful)
Date: 
Message-ID: <1991Feb21.000741.455@Neon.Stanford.EDU>
······@cs.utexas.edu (Timothy Tin-Wai Chan) writes:


>     Since someone mentioned about mapping, I want to take this
>opportunity to ask a question I've always wanted an answer for:

>          Which CL function runs faster, DOLIST or MAP...?

>(I'm doing quite a big CL program that loops extensively and I'd like to
> speed up my program.  I'm not sure if I should use DOLIST or MAP...
> in situations when I can use either.)

There is no single answer to this question.

If the body of the loop is large compared to the cost of the loop
itself, then the relative costs of DOLIST or MAP don't matter.

In general, it depends on the implementation.

DOLIST is often optimized better (i.e. produces faster code) than MAP
because DOLIST is a macro (so it's inlined and in addition to saving
the function call (which might not be very expensive, anyway)
additional optimizations might be applicable).

But, meter your code.  There are probably (just a guess, since I have
no idea about your application) other places you can speed up your
code more significantly than by switching between MAP and DOLIST.

>-- 
>----------------------------------------------------------------------
>"Greater love has no man known, than a man lay his life down for his
> friends." (John 15:13)                               --- . ____
>-- Timothy Chan (·······@ccwf.cc.utexas.edu)          /  / / / /
From: Jeff Dalton
Subject: Re: Speed of DOLIST vs. MAP... (was: Mapping is beautiful)
Date: 
Message-ID: <4205@skye.ed.ac.uk>
In article <····················@Neon.Stanford.EDU> ········@Neon.Stanford.EDU (Michael Greenwald) writes:

>DOLIST is often optimized better (i.e. produces faster code) than MAP
>because DOLIST is a macro (so it's inlined and in addition to saving
>the function call (which might not be very expensive, anyway)
>additional optimizations might be applicable).

But it's very common for MAPC to be compiled in-line, as if it were a
macro, when possible.  Franz Lisp did this.  I'm sure at least some
Common Lisps do also.