unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tianxiang Xiong <tianxiang.xiong@gmail.com>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Performance issue w/ `cl-loop`s `collect...into`
Date: Mon, 9 Apr 2018 08:33:17 -0700	[thread overview]
Message-ID: <CACMkxiznAbKURbKydMhaAXsCK-UbEsx1DE5Dvf5cTFBuoqTP+Q@mail.gmail.com> (raw)
In-Reply-To: <CACMkxizwi+FDFN9rdkRqy4Vj8BXGmV073xaw_aj1WPTryMm-_g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2069 bytes --]

I also figured out what the `(progn ... t)` pattern does. Here's a
macroexpansion w/ it:

(macroexpand-1 '(cl-loop for i in '(1 2 3) collect i))

(cl-block nil
  (let*
      ((--cl-var--
        '(1 2 3))
       (i nil)
       (--cl-var-- nil))
    (while
        (consp --cl-var--)
      (setq i
            (car --cl-var--))
      (push i --cl-var--)
      (setq --cl-var--
            (cdr --cl-var--)))
    (nreverse --cl-var--)))

And one w/out it:

(macroexpand-1 '(cl-loop for i in '(1 2 3) collect i))

(cl-block nil
  (let*
      ((--cl-var--
        '(1 2 3))
       (i nil)
       (--cl-var-- nil))
    (while
        (and
         (consp --cl-var--)
         (progn
           (setq i
                 (car --cl-var--))
           (push i --cl-var--)))
      (setq --cl-var--
            (cdr --cl-var--)))
    (nreverse --cl-var--)))

Apparently `cl--loop-build-ands` uses this pattern
<http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/cl-macs.el?h=emacs-26#n1723>
to determine whether clauses go into an `and` or not 🤷. Of course 🙄!


On Mon, Apr 9, 2018 at 8:28 AM, Tianxiang Xiong <tianxiang.xiong@gmail.com>
wrote:

> Here's the result of `benchmark-run` on the new code:
>
> (benchmark-run 10 (cl-loop for i in (number-sequence 1 1E6)
>                      collect i))
>
> ;; => (10.488984668 6 3.555157208999999)
>
> and old code:
>
> (benchmark-run 10 (cl-loop for i in (number-sequence 1 1E6)
>                      collect i))
>
> ;; => (14.876455789000001 25 2.328459104999999)
>
> So there actually seems to be an improvement due to less GC.
>
> On Mon, Apr 9, 2018 at 5:22 AM, Basil L. Contovounesios <contovob@tcd.ie>
> wrote:
>
>> Tianxiang Xiong <tianxiang.xiong@gmail.com> writes:
>>
>> > Is there a function to easily time operations in Emacs Lisp? Something
>> > like Clojure's `core/time`?
>>
>> There are the macros benchmark-run and benchmark-run-compiled, as
>> mentioned under (info "(elisp) Profiling").
>>
>> --
>> Basil
>>
>
>

[-- Attachment #2: Type: text/html, Size: 7640 bytes --]

  reply	other threads:[~2018-04-09 15:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08  0:51 Performance issue w/ `cl-loop`s `collect...into` Tianxiang Xiong
2018-04-08  3:26 ` Clément Pit-Claudel
2018-04-08  5:56   ` Tianxiang Xiong
2018-04-08  6:12     ` Clément Pit-Claudel
2018-04-08  8:50       ` Tianxiang Xiong
2018-04-08 13:19         ` Clément Pit-Claudel
2018-04-08 16:07         ` Stefan Monnier
2018-04-08 19:58           ` Tianxiang Xiong
2018-04-08 21:13             ` Stefan Monnier
2018-04-08 23:29               ` Tianxiang Xiong
2018-04-09  1:10                 ` Tianxiang Xiong
2018-04-09  1:59                   ` Stefan Monnier
2018-04-09  2:16                     ` Tianxiang Xiong
2018-04-09  2:20                       ` Stefan Monnier
2018-04-09  3:34                         ` Tianxiang Xiong
2018-04-09  3:38                           ` Tianxiang Xiong
2018-04-09 12:07                           ` Stefan Monnier
2018-04-09 12:22                           ` Basil L. Contovounesios
2018-04-09 15:28                             ` Tianxiang Xiong
2018-04-09 15:33                               ` Tianxiang Xiong [this message]
2018-04-14  7:01                                 ` Tianxiang Xiong

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACMkxiznAbKURbKydMhaAXsCK-UbEsx1DE5Dvf5cTFBuoqTP+Q@mail.gmail.com \
    --to=tianxiang.xiong@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=emacs-devel@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).