From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: emacs evaluating Date: Sat, 07 Feb 2009 23:23:46 +0100 Organization: Informatimago Message-ID: <87bptdga31.fsf@galatea.local> References: <87prhufhzk.fsf@galatea.local> <868woinf00.fsf@timbral.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1234046531 10246 80.91.229.12 (7 Feb 2009 22:42:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Feb 2009 22:42:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 07 23:43:26 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LVvsA-00066R-DJ for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2009 23:42:02 +0100 Original-Received: from localhost ([127.0.0.1]:51808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LVvqr-00034E-41 for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2009 17:40:41 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed1-b.proxad.net!nnrp20-2.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Cancel-Lock: sha1:NzhjN2VmNzNjN2Q5ZTdkOGU2MGJiZWQ1MGJiMDNmMTc4NGE3M2ZlNg== Original-Lines: 110 Original-NNTP-Posting-Date: 07 Feb 2009 23:23:47 MET Original-NNTP-Posting-Host: 88.182.134.169 Original-X-Trace: 1234045427 news-2.free.fr 24208 88.182.134.169:63416 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:166680 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61987 Archived-At: Evans Winner writes: > pjb@informatimago.com (Pascal J. Bourguignon) writes: > > To compile a function: (byte-compile 'your-function) C-x > C-e > > I had never thought of this. I think I really must not > understand compilation very clearly. I think I grasp that > an entire file full of functions will load faster if it is > compiled first, but what does interactively compiling a > single function buy me? Depends. > Does it exist in a different form > in the image when you do that? Yes. Evaluate the following forms: (defun fact (x) (if (< x 1) (/ x 0) (* x (fact (1- x))))) (symbol-function 'fact) (byte-compile 'fact) (symbol-function 'fact) > Does it execute faster? Possibly. Well the purpose is definitely to make it faster, and in most cases, it might succeed. However, if you must take into account the time taken by byte-compile itself, it might not be faster globally. In some cases, it may be better not to compile. > (This is not a facetious question, by the way.) Er, maybe > it has to do with debugging macros or something...? It has an impact on the debugging yes. Compiled functions leave less information to the debugger, so it may be harder to debug them. Evaluate the following forms in turn. (defun fact (x) (if (< x 1) (/ x 0) (* x (fact (1- x))))) (setq debug-on-error t) (fact 5) (byte-compile 'fact) (fact 5) (you can type q to exit from the debugger ; this is not a form) Then try to evaluate the following forms in turn: (defun get-internal-real-time () (destructuring-bind (hi lo msec) (current-time) (+ (/ msec 1000000.0) lo (* hi 65536.0)))) (defmacro time (&rest body) "Common-Lisp: time evaluates form in the current environment (lexical and \ dynamic). A call to time can be compiled. DO: time prints various timing data and other information to trace output. The nature and format of the printed information is implementation-defined . Implementations are encouraged to provide such information as elapsed real time, machine run time, and storage management statistics. " (let ((start (gensym)) (result (gensym)) (stop (gensym)) (time (gensym))) `(let* ((,start (get-internal-real-time)) (,result (progn ,@body)) (,stop (get-internal-real-time)) (,time (- ,stop ,start)) ) (insert (format "Time: %e ms\n" (* 1000 ,time)))))) (defun fact (x) (if (< x 1) 1 (* x (fact (1- x))))) (time (fact 2000)) (byte-compile 'fact) (time (fact 2000)) -- __Pascal Bourguignon__