From: ······@gmail.com
Subject: Explain why calling a named function conses and lambda doesn't?!?!?!?!
Date: 
Message-ID: <1190934734.942081.25460@k79g2000hse.googlegroups.com>
CHESS> (defun black ()
	 (logior (aref *black* *PAWN*)
	  (aref *black* *KNIGHT*)
	  (aref *black* *BISHOP*)
	  (aref *black* *ROOK*)
	  (aref *black* *QUEEN*)))

CHESS> (time (dotimes (i 64) (black)))
Evaluation took:
  0.0 seconds of real time
  0.0 seconds of user run time
  0.0 seconds of system run time
  0 calls to %EVAL
  0 page faults and
  4,128 bytes consed.
NIL
CHESS> (time (dotimes (i 64) (funcall (lambda ()
					(logior (aref *black* *PAWN*)
						(aref *black* *KNIGHT*)
						(aref *black* *BISHOP*)
						(aref *black* *ROOK*)
						(aref *black* *QUEEN*))))))

Evaluation took:
  0.0 seconds of real time
  0.0 seconds of user run time
  0.0 seconds of system run time
  0 calls to %EVAL
  0 page faults and
  0 bytes consed.
NIL

From: Barry Margolin
Subject: Re: Explain why calling a named function conses and lambda doesn't?!?!?!?!
Date: 
Message-ID: <barmar-5A7572.20340027092007@comcast.dca.giganews.com>
In article <·······················@k79g2000hse.googlegroups.com>,
 ······@gmail.com wrote:

> CHESS> (defun black ()
> 	 (logior (aref *black* *PAWN*)
> 	  (aref *black* *KNIGHT*)
> 	  (aref *black* *BISHOP*)
> 	  (aref *black* *ROOK*)
> 	  (aref *black* *QUEEN*)))
> 
> CHESS> (time (dotimes (i 64) (black)))
> Evaluation took:
>   0.0 seconds of real time
>   0.0 seconds of user run time
>   0.0 seconds of system run time
>   0 calls to %EVAL
>   0 page faults and
>   4,128 bytes consed.
> NIL
> CHESS> (time (dotimes (i 64) (funcall (lambda ()
> 					(logior (aref *black* *PAWN*)
> 						(aref *black* *KNIGHT*)
> 						(aref *black* *BISHOP*)
> 						(aref *black* *ROOK*)
> 						(aref *black* *QUEEN*))))))
> 
> Evaluation took:
>   0.0 seconds of real time
>   0.0 seconds of user run time
>   0.0 seconds of system run time
>   0 calls to %EVAL
>   0 page faults and
>   0 bytes consed.
> NIL

Does this still happen if you compile the BLACK function?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Juho Snellman
Subject: Re: Explain why calling a named function conses and lambda doesn't?!?!?!?!
Date: 
Message-ID: <slrnffoj6n.qc0.jsnell@sbz-30.cs.Helsinki.FI>
······@gmail.com <······@gmail.com> wrote:
> CHESS> (defun black ()
> 	 (logior (aref *black* *PAWN*)
> 	  (aref *black* *KNIGHT*)
> 	  (aref *black* *BISHOP*)
> 	  (aref *black* *ROOK*)
> 	  (aref *black* *QUEEN*)))
>
> CHESS> (time (dotimes (i 64) (black)))
[...]
>   4,128 bytes consed.

The consing numbers reported by sbcl, which you seem to be using, are
not exact, but can vary by a couple of pages (a page is 4096 bytes on
most sbcl platfroms). Try testing 640 iterations instead.

-- 
Juho Snellman
From: Tim Bradshaw
Subject: Re: Explain why calling a named function conses and lambda doesn't?!?!?!?!
Date: 
Message-ID: <1191232655.692483.116240@50g2000hsm.googlegroups.com>
On Sep 28, 12:12 am, ······@gmail.com wrote:

>
> CHESS> (time (dotimes (i 64) (black)))
> ...]
>   4,128 bytes consed.
> NIL
> CHESS> (time (dotimes (i 64) (funcall (lambda ()
>                                         (logior (aref *black* *PAWN*)
>                                                 (aref *black* *KNIGHT*)
>                                                 (aref *black* *BISHOP*)
>                                                 (aref *black* *ROOK*)
>                                                 (aref *black* *QUEEN*))))))
>
> [...]
>   0 bytes consed.

To elaborate on Barry's hint: it's fairly likely that TIME tries to
compile its argument, so you're measuring something meaningful.  In
the first case TIME doesn't will compile the DOTMIMES, but will *not*
compile the function BLACK.  In the second case, it will compile the
anonymous function.

So compile BLACK and see what the answer is.

This (not compiling things before timing/profiling them, and not
realising that you haven't) is a relatively common pitfall.

--tim