[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: consing with +

>>Since + has &rest arguments, it may entail consing.  I'm certainly >>getting
>>enough garbage collection in inner numerical loops to suggest this.
>>(1) Does +, indeed, entail consing?  (If not, then DOTIMES must be the
>>culprit, which is even less likely.) 
>>(2) If (1) is true, is there any way to force + to be a nonconsing >>binary

>+ does not cons due to its rest argument. If the result is
>other than a fixnum or short float, however, storage for the result
>will be consed.

I proceeded to do this:

* (time (let ((a 1) (b 2) (c 3) (d 4) (e 5) (f 6) (g 7) (h 8))
          (+ a b c d e f g h)))
(LET ((A 1) (B 2) (C 3) (D 4) (E 5) (F 6) (G 7) (H 8)) (+ A B C D E F
G)) took 0 milliseconds (0.000 seconds) to run.

Still no consing, even in the non-binary case.  So then I decided to see
if the compiler was noting that since + is an associative binary
operation, it could just do a pairwise recursive application kind of
thing on some sub-function.  So I did:

* (trace +)

to verify or refute my theory.

Don't do this.  It is slightly worse than (eval -), because you cannot
simply abort the operation.  You would have to be able to (untrace) to
do this, but the listener is spitting much to much information at you
for that to be possible.  Something like "calling (+ 0 9 2)" ad

I don't care about the infinite noise - I asked for that 8), I just want
to know what the compiler is doing.