From: Dmitry V. Gorbatovsky
Subject: newbie enigma here
Date: 
Message-ID: <eil3uv$s00$1@aioe.server.aioe.org>
Please help me to explain this behavior (last cmucl on debian)
It seems like function defined by name is about 100 times slower
than function running nameless in repl ????


cl-user> (defun remove-zeros (list-a list-b)
           (let ((final-list nil)) 
             (loop for item1 in list-a
                   and item2 in list-b
                   do (when (and (not (= (nth 2 item1) 0))
                                 (not (= (nth 2 item2) 0)))
                        (push (list
                               (nth 2 item1)
                               (nth 2 item2)) 
                              final-list)))))

REMOVE-ZEROS
cl-user> (time (remove-zeros list-aa list-bb))
                                        ; Compiling LAMBDA NIL: 
                                        ; Compiling Top-Level Form: 

                                        ; Evaluation took:
                                        ;   0.03 seconds of real time
                                        ;   0.016001 seconds of user run time
                                        ;   0.0 seconds of system run time
                                        ;   16,570,074 CPU cycles
                                        ;   0 page faults and
                                        ;   91,608 bytes consed.
                                        ; 
NIL
cl-user> (time (let ((final-list nil)) 
                 (loop for item1 in list-aa
                       and item2 in list-bb
                       do (when (and (not (= (nth 2 item1) 0))
                                     (not (= (nth 2 item2) 0)))
                            (push (list
                                   ;;                       (nth 0 item1)
                                   (nth 2 item1)
                                   (nth 2 item2)) 
                                  final-list)))))
                                        ; Compiling LAMBDA NIL: 
                                        ; Compiling Top-Level Form: 

                                        ; Evaluation took:
                                        ;   0.0 seconds of real time
                                        ;   0.0 seconds of user run time
                                        ;   0.0 seconds of system run time
                                        ;   157,817 CPU cycles
                                        ;   0 page faults and
                                        ;   6,304 bytes consed.
                                        ; 
NIL
cl-user> 


Thanks ,Dmitry

From: Juho Snellman
Subject: Re: newbie enigma here
Date: 
Message-ID: <slrneks5hj.834.jsnell@sbz-30.cs.Helsinki.FI>
Dmitry V. Gorbatovsky <·········@midasitech.com> wrote:
> Please help me to explain this behavior (last cmucl on debian)
> It seems like function defined by name is about 100 times slower
> than function running nameless in repl ????

CMUCL doesn't normally compile code entered at the REPL (which
includes the function REMOVE-ZEROS that you defined), but it *does*
compile the body of a TIME form.

> cl-user> (defun remove-zeros (list-a list-b)
>            (let ((final-list nil)) 
>              (loop for item1 in list-a
>                    and item2 in list-b
>                    do (when (and (not (= (nth 2 item1) 0))
>                                  (not (= (nth 2 item2) 0)))
>                         (push (list
>                                (nth 2 item1)
>                                (nth 2 item2)) 
>                               final-list)))))
>
> REMOVE-ZEROS

(COMPILE 'REMOVE-ZEROS)

-- 
Juho Snellman
From: ········@gmail.com
Subject: Re: newbie enigma here
Date: 
Message-ID: <1162749084.156421.12900@b28g2000cwb.googlegroups.com>
You can also do this slightly odd thing:

  (funcall (compile (defun fact (n) (if (zerop n) 1 (* n (fact (1-
n)))))) 5)

Not that you'd want to, but it's sort of fun. :-)
From: Dmitry V. Gorbatovsky
Subject: Re: newbie enigma here
Date: 
Message-ID: <eil5i5$18s$1@aioe.server.aioe.org>
Juho Snellman wrote:

> Dmitry V. Gorbatovsky <·········@midasitech.com> wrote:
>> Please help me to explain this behavior (last cmucl on debian)
>> It seems like function defined by name is about 100 times slower
>> than function running nameless in repl ????
> 
> CMUCL doesn't normally compile code entered at the REPL (which
> includes the function REMOVE-ZEROS that you defined), but it *does*
> compile the body of a TIME form.
> 
>> cl-user> (defun remove-zeros (list-a list-b)
>>            (let ((final-list nil))
>>              (loop for item1 in list-a
>>                    and item2 in list-b
>>                    do (when (and (not (= (nth 2 item1) 0))
>>                                  (not (= (nth 2 item2) 0)))
>>                         (push (list
>>                                (nth 2 item1)
>>                                (nth 2 item2))
>>                               final-list)))))
>>
>> REMOVE-ZEROS
> 
> (COMPILE 'REMOVE-ZEROS)
> 

When I compile it as you suggest, enigma is gone :)
Thanks a lot,Dmitry.