From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] use tail pointer for LOOP Date: Thu, 17 Jun 2010 11:22:32 +0200 Message-ID: <20100617092232.GA27846@tomas> References: <4C018D79.7040409@censorshipresearch.org> <4C018FD3.1020305@censorshipresearch.org> <4C01AA28.6030002@censorshipresearch.org> <9718A5AD-7A74-470B-A32D-DA14266506A3@raeburn.org> <4C01B609.6070303@censorshipresearch.org> <20100616174420.GA2847@tomas> <87fx0msv9z.fsf@lola.goethe.zz> <20100617051021.GA26623@tomas> <87mxuu5dq3.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XF85m9dhOBO43t/C" X-Trace: dough.gmane.org 1276766554 18981 80.91.229.12 (17 Jun 2010 09:22:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 17 Jun 2010 09:22:34 +0000 (UTC) Cc: tomas@tuxteam.de, emacs-devel@gnu.org To: Thien-Thi Nguyen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 17 11:22:30 2010 connect(): No such file or directory 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 1OPBIr-0003qj-I8 for ged-emacs-devel@m.gmane.org; Thu, 17 Jun 2010 11:22:29 +0200 Original-Received: from localhost ([127.0.0.1]:47509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPBIq-0004ne-8b for ged-emacs-devel@m.gmane.org; Thu, 17 Jun 2010 05:22:28 -0400 Original-Received: from [140.186.70.92] (port=50689 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPBIa-0004kP-4Z for emacs-devel@gnu.org; Thu, 17 Jun 2010 05:22:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OPBIW-0005vO-ID for emacs-devel@gnu.org; Thu, 17 Jun 2010 05:22:12 -0400 Original-Received: from alextrapp1.equinoxe.de ([217.22.192.104]:44404 helo=www.elogos.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OPBIW-0005ud-7O for emacs-devel@gnu.org; Thu, 17 Jun 2010 05:22:08 -0400 Original-Received: by www.elogos.de (Postfix, from userid 1000) id 14E149004D; Thu, 17 Jun 2010 11:22:32 +0200 (CEST) Content-Disposition: inline In-Reply-To: <87mxuu5dq3.fsf@ambire.localdomain> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:126071 Archived-At: --XF85m9dhOBO43t/C Content-Type: multipart/mixed; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 17, 2010 at 09:18:28AM +0200, Thien-Thi Nguyen wrote: > () tomas@tuxteam.de > () Thu, 17 Jun 2010 07:10:21 +0200 >=20 > Still, reversing seems to be worth it (by some 30 percent). > Unless we find some way to streamline the tail pointer better. >=20 > How does this variant fare? >=20 > (defun copy3 (lst) > "Return a copy of LST." > (let* ((box (list nil)) > (tp box)) > (while lst > (setq tp (cdr (nconc tp (list (pop lst)))))) > (cdr box))) Cute. You all are successfully keeping me from work. Enjoing it ;-) Here are the results. Attached the modified source. copy1: (1.058881 5 0.7366780000000048) copy2: (1.27958 6 0.8913360000000026) copy3: (1.337353 6 0.9249420000000015) Still the reverse version is the winner. Yours seems to be a tad slower (although I wouldn't know whether it's in the noise). But it looks so sharp ;-) Thanks, regards -- tom=E1s --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bm.el" ;; This buffer is for notes you don't want to save, and for Lisp evaluation. ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer. (defun copy1 (lst) "Build up a copy of lst by consing up in reverse order, then reversing" (let ((res)) (while lst (setq res (cons (car lst) res) lst (cdr lst))) (nreverse res))) (defun copy2 (lst) "Build up a copy of lst by consing up in order, keeping a tail pointer" (when lst (let ((res) (tail)) (setq res (cons (car lst) nil) tail res lst (cdr lst)) (while lst (setcdr tail (cons (car lst) nil)) (setq tail (cdr tail) lst (cdr lst))) res))) (defun copy3 (lst) "Return a copy of LST." (let* ((box (list nil)) (tp box)) (while lst (setq tp (cdr (nconc tp (list (pop lst)))))) (cdr box))) (defun do-benchmark (n) (let ((lst)) (while (> n 0) (setq lst (cons n lst) n (1- n))) (garbage-collect) (message (concat "copy1: %S\n" "copy2: %S\n" "copy3: %S\n") (benchmark-run (copy1 lst)) (benchmark-run (copy2 lst)) (benchmark-run (copy3 lst))))) (byte-compile 'copy1) (byte-compile 'copy2) (byte-compile 'copy3) (byte-compile 'do-benchmark) (do-benchmark 1000000) --CE+1k2dSO48ffgeK-- --XF85m9dhOBO43t/C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFMGelYBcgs9XrR2kYRAiIrAJ4xuNdt18SroyjwV5+PtbjUfw3qJQCfd5x8 xDMU1QfpOwEEgyeFpW1rXsE= =lmS+ -----END PGP SIGNATURE----- --XF85m9dhOBO43t/C--