From: Chong Yidong <cyd@stupidchicken.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org, Miles Bader <miles@gnu.org>
Subject: Re: return
Date: Fri, 03 Dec 2010 18:00:22 -0500 [thread overview]
Message-ID: <87r5dy7989.fsf@stupidchicken.com> (raw)
In-Reply-To: <jwvaakmo65r.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 03 Dec 2010 17:29:55 -0500")
Stefan Monnier <monnier@IRO.UMontreal.CA> 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.
next prev parent reply other threads:[~2010-12-03 23:00 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-26 8:57 return Lars Magne Ingebrigtsen
2010-11-26 9:19 ` return Tassilo Horn
2010-12-04 2:36 ` return Fren Zeee
2010-12-04 3:04 ` Common vs Emacs Lisp (was: Re: return) Chad Brown
2010-12-04 19:48 ` Fren Zeee
2010-12-05 10:20 ` Chad Brown
2010-12-04 6:18 ` return Stephen J. Turnbull
2010-12-04 6:49 ` return Leo
2010-11-26 9:24 ` return Miles Bader
2010-11-26 9:36 ` return Lars Magne Ingebrigtsen
2010-11-26 9:54 ` return Miles Bader
2010-11-26 10:13 ` return Lars Magne Ingebrigtsen
2010-11-26 9:44 ` return Tassilo Horn
2010-11-26 14:59 ` return Stefan Monnier
2010-11-26 15:45 ` return Lars Magne Ingebrigtsen
2010-11-26 18:40 ` return Stefan Monnier
2010-11-27 1:31 ` return Lars Magne Ingebrigtsen
2010-11-27 2:49 ` return Stefan Monnier
2010-11-27 3:06 ` return Lars Magne Ingebrigtsen
2010-12-03 18:41 ` return Chong Yidong
2010-12-03 18:43 ` return Miles Bader
2010-12-03 19:46 ` return Chong Yidong
2010-12-03 21:26 ` return Chong Yidong
2010-12-03 22:29 ` return Stefan Monnier
2010-12-03 23:00 ` Chong Yidong [this message]
2010-12-04 1:35 ` return Stefan Monnier
2010-12-04 3:23 ` return Chong Yidong
2010-12-06 16:13 ` return Davis Herring
2010-12-06 17:15 ` return Chong Yidong
2010-12-03 22:44 ` return Chong Yidong
2010-12-04 9:22 ` return Helmut Eller
-- strict thread matches above, loose matches on Subject: below --
2010-11-26 23:01 return MON KEY
2010-12-05 23:55 Return MON KEY
2010-12-06 1:48 ` Return Stephen J. Turnbull
2010-12-06 5:50 ` Return MON KEY
2010-12-06 7:20 ` Return Stephen J. Turnbull
2010-12-06 9:00 ` Return David Kastrup
2010-12-06 19:11 ` Return Stefan Monnier
2010-12-06 19:09 ` Return Stefan Monnier
2010-12-06 19:19 ` Return Chong Yidong
2010-12-06 20:27 ` Return Stefan Monnier
2010-12-07 4:47 ` Return Miles Bader
2010-12-07 9:17 ` Return David Kastrup
2010-12-07 17:10 ` Return Stefan Monnier
2010-12-07 22:15 ` Return David Kastrup
2010-12-08 15:50 ` Return Fren Zeee
2010-12-09 22:38 ` Return Stefan Monnier
2010-12-10 1:41 ` Return Stephen J. Turnbull
2010-12-10 3:44 ` Return Stefan Monnier
2010-12-10 8:28 ` Return Stephen J. Turnbull
2010-12-23 5:39 ` Return Fren Zeee
2010-12-07 12:44 ` Return Stephen J. Turnbull
2010-12-07 14:38 ` Return David Kastrup
2010-12-07 16:14 ` Return Stephen J. Turnbull
2010-12-07 17:11 ` Return tomas
2010-12-07 2:42 ` Return MON KEY
2010-12-07 14:34 ` Return Stephen J. Turnbull
2010-12-07 15:54 ` Return David Kastrup
2010-12-07 16:30 ` Return Stephen J. Turnbull
2010-12-08 13:42 ` Return Richard Stallman
2010-12-10 7:42 ` Return Daniel Colascione
2010-12-07 22:55 ` Return MON KEY
2010-12-08 7:28 ` Return Stephen J. Turnbull
2010-12-08 18:11 ` Return MON KEY
2010-12-09 8:37 ` Return Stephen J. Turnbull
2010-12-07 23:21 ` Return Samuel Bronson
2010-12-08 8:06 ` Return Stephen J. Turnbull
2010-12-08 20:51 ` Return Samuel Bronson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r5dy7989.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=miles@gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.