From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: Playing with guile (vs python). Generate file for GDP suitable for gnuplot. Date: Mon, 06 Mar 2017 22:02:25 +0100 Message-ID: <878toi9l0e.fsf@pobox.com> References: <8760kg4y1b.fsf@gnu.org> <878toi5xaw.fsf@zigzag.favinet> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488834187 14183 195.159.176.226 (6 Mar 2017 21:03:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 6 Mar 2017 21:03:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Mar 06 22:03:00 2017 Return-path: Envelope-to: guile-user@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 1ckzmU-0002dj-5L for guile-user@m.gmane.org; Mon, 06 Mar 2017 22:02:58 +0100 Original-Received: from localhost ([::1]:46120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckzma-0002WI-C6 for guile-user@m.gmane.org; Mon, 06 Mar 2017 16:03:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckzmA-0002W7-E7 for guile-user@gnu.org; Mon, 06 Mar 2017 16:02:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckzm7-0006EJ-4X for guile-user@gnu.org; Mon, 06 Mar 2017 16:02:38 -0500 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:59165 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckzm7-0006Do-1T for guile-user@gnu.org; Mon, 06 Mar 2017 16:02:35 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 06D377317C for ; Mon, 6 Mar 2017 16:02:34 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=qLwreqxINogd54FVzB2cre5KNlc=; b=s8jcah Wie+g1td2z3KChqN+fI+8JIKuUwWkXUNgB0elotQGoiOzLC/dHZ6iGRqSAZVyoAO NJTAGMw9Mc1xuqM4iA1Qtes7sVbjq0aAMwDX1/JTaFfQmIzBLlOzB0ztdcEJNpd1 t5B6xEVCb6VzCu24SEvAy5n4uSadxiRv8PlRs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=XuAGFRrDOeUf2XGdKYCQf/lU2lSicL3q tZoaHU5XLc9OUhuEs+g1HCVhKyHlY6djIme+KFgOz3yYnzG/lNfIqbB/0bY39gIs XVCI8ez6m49RYmNMwxDAxn8W+NNeAwXu/Wc1Z/BpYtgfT9VwdtcqSHKloJ42r8cL PwtpAxD2GdI= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id E3FF57317A for ; Mon, 6 Mar 2017 16:02:33 -0500 (EST) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id DF3D573175 for ; Mon, 6 Mar 2017 16:02:32 -0500 (EST) In-Reply-To: <878toi5xaw.fsf@zigzag.favinet> (Thien-Thi Nguyen's message of "Mon, 06 Mar 2017 14:50:31 +0100") X-Pobox-Relay-ID: 37BEDC46-02B0-11E7-BCAB-B667064AB293-02397024!pb-sasl1.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.66 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13431 Archived-At: On Mon 06 Mar 2017 14:50, Thien-Thi Nguyen writes: > FWIW, we can also use SRFI 13 to save a few cycles: > > (use-modules (ice-9 rdelim) (srfi srfi-13)) > > (define (file->lines filename) > "Return a list of lines contained in a file." > (call-with-input-file > filename > (lambda (p) > (let loop ((acc '())) > (let ((line (read-line p))) > (if (eof-object? line) > (reverse! acc) ; rv > (loop (cons (string-drop-right line 1) > acc)))))))) > > This variant is also more stack-conserving (amenable to TCO), > which should afford some additional speedup. Interestingly the timings are not dissimilar in 2.2; consider this most microbenchmarky of cases: (use-modules (ice-9 match)) (define test (iota #e1e6)) (define (copy-list/accum xs) (let lp ((xs xs) (out '())) (match xs ((x . xs) (lp xs (cons x out))) (() (reverse! out))))) (define (copy-list/recur xs) (let lp ((xs xs)) (match xs ((x . xs) (cons x (lp xs))) (() '())))) Doing a ,time (length (copy-list test) at the REPL for both these two copy-list impls gives me: real times (s) ------------------------------------ copy-list/recur | copy-list/accum .................................... 0.067212s 0.046110s 0.077659s 0.059750s 0.065923s 0.040371s 0.066098s 0.062963s 0.062718s 0.040980s The recursive version is still slower ATM but I think that will go away once I manage to avoid running the function prelude each time; not sure. Anyway, I am happy recommending recursing now :) Andy