emacs-pretest-bug
[Top][All Lists]
Advanced

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

doc of defsubst


From: Dave Love
Subject: doc of defsubst
Date: Tue, 09 Nov 2004 17:21:08 +0000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.2 (gnu/linux)

I think it would be worth clarifying in lispref how defsubst works
with an example.

For instance, after

 (defsubst sumin (a b)
   (- b a))

a call

 (sumin 1 2)

is equivalent to

 (let ((a 1)
       (b 2))
    (- b a))

This makes it clear that the open coding involves variable binding,
which is easy to miss and might be important if you're really
concerned with efficiency.  It also demonstrates the difference
between the open coding and the result of a macro expansion or using
`(- b a)' directly.

In some circumstances the binding might be a significant expense you'd
want to avoid:

(benchmark-run-compiled 1 (dotimes (i 1000000) (- i 1)))
  => (0.337898 0 0.0)
(benchmark-run-compiled 1 (dotimes (i 1000000) (sunim 1 i)))
  => (0.705731 0 0.0)

(The time for the loop with `sunim' defined using defun is 0.94.)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]