From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tianxiang Xiong Newsgroups: gmane.emacs.devel Subject: Re: Performance issue w/ `cl-loop`s `collect...into` Date: Sat, 14 Apr 2018 00:01:32 -0700 Message-ID: References: <41631665-6cd6-7096-8866-5ab9559a14ef@gmail.com> <1d5b85f5-62cd-f2f3-0b71-9e2a2cf2ef9e@gmail.com> <87r2nobmcq.fsf@tcd.ie> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="f4030438f2081211450569c98ffb" X-Trace: blaine.gmane.org 1523689217 13403 195.159.176.226 (14 Apr 2018 07:00:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Apr 2018 07:00:17 +0000 (UTC) Cc: Stefan Monnier , Emacs developers To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 14 09:00:13 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7FAR-0003Lp-UI for ged-emacs-devel@m.gmane.org; Sat, 14 Apr 2018 09:00:12 +0200 Original-Received: from localhost ([::1]:38229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7FCY-0000XN-Hz for ged-emacs-devel@m.gmane.org; Sat, 14 Apr 2018 03:02:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7FBo-0000Wo-43 for emacs-devel@gnu.org; Sat, 14 Apr 2018 03:01:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f7FBn-0005eD-1h for emacs-devel@gnu.org; Sat, 14 Apr 2018 03:01:36 -0400 Original-Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:39461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f7FBm-0005dl-Om for emacs-devel@gnu.org; Sat, 14 Apr 2018 03:01:34 -0400 Original-Received: by mail-wr0-x22c.google.com with SMTP id q6so1053348wrd.6 for ; Sat, 14 Apr 2018 00:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=MHP4oNnqLpD+2OPnrl6DSveDy3MCJ2C+dYnXl74mLPY=; b=iO4JyWYsIrW1FDICzT2B3jARG9BBqKzI4FNofkm3R5Ti27SPgHfo1HfKwz+pXtxZ00 +mC+qfiy5OdLbDAg5V+Gb6gPWdWICZZ3juxPU26N11JZAoxwmV1P9cxO+VNIip6on7cW ujAxFhfMuHzcYrSWl++BaZgZ9NZwbnlBttUoqMALAGc2rbjHcnBhAqbKw911dLT4Xv+G xoq5FoWfKnrFSI7TPQ4XKqE+zZObhfmFem9VYSS1b6IFa2H5rZ95TCEiG89M25ysm7nz tQYJs6KdXXC7CMFiCn4LifoCL7FpeIABqN9Qf3/OuIUEUMrrajduSbnyqpuralk5B7/D 3acA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=MHP4oNnqLpD+2OPnrl6DSveDy3MCJ2C+dYnXl74mLPY=; b=h/U9QPRG3fcW46LQBlL6X0oQuNVLKl9lQ3xA9MAs6hRfreaXESBwDv48GlLurwf4Nj U6tsMP7fu8q8PbXgDGMKHnBd88naDoGcAAJL++lJTPyadHDVqKLbHSqBVag+9rESU87Y 24EvxOCHE/casyXQHOlRdR1sidoKE8Gb5D6hK4CzrhLTIP+W6sgMHtQlM75jYEpctBBh l1e24jyD6/J0Hlv0rpju4+lFG/Ad/8INyuH7ogyYW0op0yfyCJqWRlJU3YlFHlUw0W+j pTplh12Xqa6zHFXR2C3C25ACHx2WAmIMj2ajWem2K/8mdMB1q+FZDTvc1ADctDtBZCfr L4Ug== X-Gm-Message-State: ALQs6tBIkpx8ZKxxbXVEyRfqKDsdL554gqPOWSHYHq0+gzm0P38afW2a OyUGVCF1Uv1GdpblV2oqH9FBQREH1Rll0e/q0Z4= X-Google-Smtp-Source: AIpwx4+NNdVfm4B5WqOc5sNR9I6/HLpJZ5fAcYli1K6jAnydMq9LUDk/KLq4T+WivoM5Qi1Xl44rz0bNK3V32G209bU= X-Received: by 10.80.202.77 with SMTP id e13mr451114edi.304.1523689293221; Sat, 14 Apr 2018 00:01:33 -0700 (PDT) Original-Received: by 10.80.152.131 with HTTP; Sat, 14 Apr 2018 00:01:32 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224582 Archived-At: --f4030438f2081211450569c98ffb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Since it appears there's no performance degradation, can we merge this? If others would like to do some testing, that'd be great. On Mon, Apr 9, 2018 at 8:33 AM, Tianxiang Xiong wrote: > 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 > > to determine whether clauses go into an `and` or not =F0=9F=A4=B7. Of cou= rse =F0=9F=99=84! > > > On Mon, Apr 9, 2018 at 8:28 AM, Tianxiang Xiong > 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)) >> >> ;; =3D> (10.488984668 6 3.555157208999999) >> >> and old code: >> >> (benchmark-run 10 (cl-loop for i in (number-sequence 1 1E6) >> collect i)) >> >> ;; =3D> (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 >> wrote: >> >>> Tianxiang Xiong writes: >>> >>> > Is there a function to easily time operations in Emacs Lisp? Somethin= g >>> > like Clojure's `core/time`? >>> >>> There are the macros benchmark-run and benchmark-run-compiled, as >>> mentioned under (info "(elisp) Profiling"). >>> >>> -- >>> Basil >>> >> >> > --f4030438f2081211450569c98ffb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Since it appears there's no performance degradation, c= an we merge this?

If others would like to do some testin= g, that'd be great.

On Mon, Apr 9, 2018 at 8:33 AM, Tianxiang Xiong <tianxiang.xiong@gmail.com> wrote:
I also fig= ured 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
=C2=A0 (let*
=C2=A0 =C2=A0 =C2=A0 ((--c= l-var--
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 '(1 2 3))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(i nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(--cl-var-- nil))
=C2=A0 =C2=A0 (w= hile
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 (consp --cl-var--)
=C2=A0 =C2=A0 =C2=A0 (setq i
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (car --cl-var--))<= /font>
=C2=A0 =C2=A0 = =C2=A0 (push i --cl-var--)
=C2=A0 =C2=A0 =C2=A0 (setq --cl-var--
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cdr --cl-va= r--)))
=C2=A0 =C2=A0 (= nreverse --cl-var--)))

And one w/out it:

(macroexpand-1 '(cl-loop for i in '(= 1 2 3) collect i))
(cl-block nil=
=C2=A0 (let*
=C2=A0 =C2=A0 =C2=A0 ((--cl-var--
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 '(1 2 3))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0(i nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(--cl-var-- nil))
=C2=A0 =C2=A0 (while
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (and
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(consp --cl-var--)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq i<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(car --cl-var--))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(pus= h i --cl-var--)))
=C2= =A0 =C2=A0 =C2=A0 (setq --cl-var--
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cdr --cl-var--)))
=C2=A0 =C2=A0 (nreverse= --cl-var--)))

Apparently `cl--loop-build-ands` uses this pattern to d= etermine whether clauses go into an `and` or not=C2=A0=F0=9F=A4=B7. Of cour= se=C2=A0=F0=9F=99=84!


On Mon, Apr 9, 2018 at 8:28= AM, Tianxiang Xiong <tianxiang.xiong@gmail.com> wro= te:
Here's the resul= t of `benchmark-run` on the new code:

(benchmark-ru= n 10 (cl-loop for i in (number-sequence 1 1E6)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0collect i))

;; =3D> (10.488984668 6 3.555157208999999)

and old code:

(benchma= rk-run 10 (cl-loop for i in (number-sequence 1 1E6)
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0collect i))<= /div>

;; =3D> (14.876455789000001 25 2.32845910499999= 9)

So there actually seems to be an improvem= ent due to less GC.

On Mon, Apr 9, 2018 at = 5:22 AM, Basil L. Contovounesios <contovob@tcd.ie> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">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



--f4030438f2081211450569c98ffb--