From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: return Date: Fri, 03 Dec 2010 18:00:22 -0500 Message-ID: <87r5dy7989.fsf@stupidchicken.com> References: <87hbeu7l84.fsf@stupidchicken.com> <87bp52ae9g.fsf@catnip.gol.com> <87r5dyfxmn.fsf@stupidchicken.com> <87ei9y5z0v.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1291417248 661 80.91.229.12 (3 Dec 2010 23:00:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 23:00:48 +0000 (UTC) Cc: emacs-devel@gnu.org, Miles Bader To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 04 00:00:39 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POecI-0002Lx-IV for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 00:00:39 +0100 Original-Received: from localhost ([127.0.0.1]:58998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POecI-0004VQ-0p for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 18:00:38 -0500 Original-Received: from [140.186.70.92] (port=44426 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POecB-0004Uz-HO for emacs-devel@gnu.org; Fri, 03 Dec 2010 18:00:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POec6-0005nN-Rz for emacs-devel@gnu.org; Fri, 03 Dec 2010 18:00:31 -0500 Original-Received: from vm-emlprdomr-03.its.yale.edu ([130.132.50.144]:33374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POec5-0005ml-Ef; Fri, 03 Dec 2010 18:00:25 -0500 Original-Received: from furball (dhcp128036014088.central.yale.edu [128.36.14.88]) (authenticated bits=0) by vm-emlprdomr-03.its.yale.edu (8.14.4/8.14.4) with ESMTP id oB3N0NNq014767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 3 Dec 2010 18:00:24 -0500 Original-Received: by furball (Postfix, from userid 1000) id 31101160675; Fri, 3 Dec 2010 18:00:23 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Fri, 03 Dec 2010 17:29:55 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.144 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133376 Archived-At: Stefan Monnier writes: > A few questions: > - how do you explain that Fwhile with internal catch is faster (1.057 < > 1.084) than without an internal catch? Or is that what you mean by > "within the margin of error"? > - You seem to be measuring time for the interpreted code, is that right? > If so, I think it would be more interesting to measure the time for > byte-code. > > The little tests I've performed seem to indicate that for interpreted > code the extra `catch' doesn't make much of a difference, but for the > compiled version of your test, the difference is around 20%. Hmm, yes, I was testing on interpreted code. Here is a new test using a byte-compiled file: (defun test-loop-nocatch () (dotimes (ii 2000000) (let ((ll '(1 2 3 4 5 6 7 8 9 10))) (while ll (setq ll (cdr ll)))))) Averaging over ten runs, this takes 1.351 +- 0.022s without an internal catch, and 1.371 +- 0.034s with an internal catch. Using the Emacs without an internal-catch, I tested on a byte-compiled version of a function with a catch inserted manually into the loop: (defun test-loop-catch () (dotimes (ii 2000000) (let ((ll '(1 2 3 4 5 6 7 8 9 10))) (while ll (catch 'exit (setq ll (cdr ll))))))) The result is 1.725 +- 0.033s. The simplistic "internal catch" implementation I used is this: *** src/eval.c 2010-10-26 22:23:09 +0000 --- src/eval.c 2010-12-03 22:59:10 +0000 *************** *** 1054,1065 **** return unbind_to (count, elt); } ! DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0, ! doc: /* If TEST yields non-nil, eval BODY... and repeat. ! The order of execution is thus TEST, BODY, TEST, BODY and so on ! until TEST returns nil. ! usage: (while TEST BODY...) */) ! (Lisp_Object args) { Lisp_Object test, body; struct gcpro gcpro1, gcpro2; --- 1054,1061 ---- return unbind_to (count, elt); } ! Lisp_Object ! internal_while (Lisp_Object args) { Lisp_Object test, body; struct gcpro gcpro1, gcpro2; *************** *** 1078,1083 **** --- 1074,1090 ---- return Qnil; } + DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0, + doc: /* If TEST yields non-nil, eval BODY... and repeat. + The order of execution is thus TEST, BODY, TEST, BODY and so on + until TEST returns nil. + usage: (while TEST BODY...) */) + (Lisp_Object args) + { + int count = SPECPDL_INDEX (); + return internal_catch (Qexit, &internal_while, args); + } + DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0, doc: /* Return result of expanding macros at top level of FORM. If FORM is not a macro call, it is returned unchanged.