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: Mon, 9 Apr 2018 08:33:17 -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="94eb2c199dc203615d05696c2005" X-Trace: blaine.gmane.org 1523287891 24956 195.159.176.226 (9 Apr 2018 15:31:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 9 Apr 2018 15:31:31 +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 Mon Apr 09 17:31:26 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 1f5YlS-0006OQ-BL for ged-emacs-devel@m.gmane.org; Mon, 09 Apr 2018 17:31:26 +0200 Original-Received: from localhost ([::1]:46966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5YnY-0003Uf-6f for ged-emacs-devel@m.gmane.org; Mon, 09 Apr 2018 11:33:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5YnI-0003TE-IU for emacs-devel@gnu.org; Mon, 09 Apr 2018 11:33:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f5YnH-0000uZ-DN for emacs-devel@gnu.org; Mon, 09 Apr 2018 11:33:20 -0400 Original-Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:35019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f5YnH-0000tt-2q for emacs-devel@gnu.org; Mon, 09 Apr 2018 11:33:19 -0400 Original-Received: by mail-wm0-x22a.google.com with SMTP id r82so17742435wme.0 for ; Mon, 09 Apr 2018 08:33:18 -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=tfnoHWXAZXLB1St5ztXztckWwj4PXUhfc9zYzOV7KAM=; b=AzUC7oBe3jHmcGnDnfXBPd3Yr5PCu3cky8aEwNs/FRCJ9KaN/bg10c/AGtngeUVX/v nNH2jdVaKJlbAuF1fUJDJh8LTup/2+ZRub8bk160YfFD0bnkmyxNw/PglKDiSAKh2m1q qV2J9Wn2/JfZBUanhN6XcAeVTrlSeGVAZxF3lSqL86t5KWN5Efo4kVL79tqYyE1hftxB RH+o3dVk0XDxO98Oc9C80q4+Q3c7Q8mU5jCzLqC3v21Yff2+ijF6ct0W1TpTZ34eZZVH svnixRZS8yi7CsIO7LUz7FoBqDCp8NR7pXHDM3mY9qYymEoW2cPyzZGcnQqYoCfJ2jtd MgAQ== 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=tfnoHWXAZXLB1St5ztXztckWwj4PXUhfc9zYzOV7KAM=; b=eh2Ip8wxcdJvMixFgEbpIgD3Tzt4qYxR/CHYdcG/Zk4ZJr0K6OogkJIbuja8u/laXb jJxXBX0drXXVpqQwcorPvsC8bFC5K6rpRw2C/SWGSSu+QAi5VP9fEd/6CrWTIXIqrAzU JZ/xoxQesB7/wJ7fUWb+nmY7icuzahHgfc9HEnW4PBbc8RPcWlzXZ+k1nCRteVm4s2Yw sbwtzbys1ESu8fiGzXgWCuoyFMUVHrlMAlwG5CKrjckN+TOCK4cEyJgP+rxai579roeR plK+9Bp+M2gcPH5ceTvVaOXaGqBZ+LqWSXQ9jb4s8B74NZVvl+h11ukyp3AkFlPvT9Pe zG1A== X-Gm-Message-State: ALQs6tABirJp7s8Iw7wZdQvKkeVudju/yYLtI4hOo4vHX+g8mPOH/LYG 9Eqbe1b5Q8LvxfXC9xomDBfjqEIy4/NHCeev2ks= X-Google-Smtp-Source: AIpwx4/YiqZS4FKHEPEEJ9XoRK7hMm31IVNjfXpjkQtbLlr1H0CuYC9x+UPftyfcEokh6Hy0J0HmOZuNr/vSaZErs9o= X-Received: by 10.80.149.84 with SMTP id v20mr7075772eda.190.1523287998029; Mon, 09 Apr 2018 08:33:18 -0700 (PDT) Original-Received: by 10.80.203.195 with HTTP; Mon, 9 Apr 2018 08:33:17 -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:c09::22a 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:224468 Archived-At: --94eb2c199dc203615d05696c2005 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 cours= e =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? Something >> > like Clojure's `core/time`? >> >> There are the macros benchmark-run and benchmark-run-compiled, as >> mentioned under (info "(elisp) Profiling"). >> >> -- >> Basil >> > > --94eb2c199dc203615d05696c2005 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I also figured out= what the `(progn ... t)` pattern does. Here's a macroexpansion w/ it:<= /div>

(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 (consp --cl-var--)
=C2=A0 =C2=A0 =C2=A0 (setq i
<= div style=3D"">=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (car --cl-var--))
=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-var--)))
=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
=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(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-var--)))
=C2=A0 =C2=A0 (nreverse --cl-var--)))

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


On Mon, Apr 9, 2= 018 at 8:28 AM, Tianxiang Xiong <tianxiang.xiong@gmail.com>= wrote:
Here'= s the result of `benchmark-run` on the new code:

(b= enchmark-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=A0collec= t i))

;; =3D> (10.488984668 6 3.555157208999999= )

and old code:

(benchmark-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=A0co= llect i))

;; =3D> (14.876455789000001 25 2.3284= 59104999999)

So there actually seems to be a= n improvement due to less GC.

On Mon, Apr 9, 2018 at 5:22 AM, Ba= sil 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").
<= br> --
Basil


--94eb2c199dc203615d05696c2005--