property list hack, profiling, compiler optimization, looking at code



On Sat, Aug 11, 2012 at 2:11 PM, Richard Fateman
<fateman at eecs.berkeley.edu>wrote:
>
> An additional observation regarding speed and  zerop1, which is defined
> this way:
>
>  (defun zerop1 (x)
>   (or (and (integerp x) (= 0 x))
>       (and (floatp x) (= 0.0 x))
>       (and ($bfloatp x) (= 0 (second x)))))
>

This is a strange definition, as for a non-zero integer, it still checks
floatp and $bfloatp.  More straightforward would be:

(defun zerop1 (x)
    (declare (inline $bfloatp))   ; worthwhile for such a common function
 (requires declaim/inline etc. @ $bfloatp)
    (cond ((fixnump x) (= 0 x))   ; a bignum can't be 0
              ((floatp x) (= 0.0 x))
              (($bfloatp x) (= 0 (second x)))
              (t nil)))

Of course, the straightforward definition isn't necessarily the fastest,
and may depend on the particular compiler and processor.

Though I find micro-optimizing like this peculiarly entertaining, I'm
pretty sure this will make no noticeable difference to the user experience,
certainly less difference than improving functionality in any one of a
number of ways.

            -s