From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: guile performance - Ackermann function: way slower than emacs, slower still if compiled Date: Thu, 06 Aug 2009 17:59:23 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1249574599 3548 80.91.229.12 (6 Aug 2009 16:03:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Aug 2009 16:03:19 +0000 (UTC) Cc: guile-devel To: Ken Raeburn Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Aug 06 18:03:10 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MZ5Qr-00064b-C1 for guile-devel@m.gmane.org; Thu, 06 Aug 2009 18:03:09 +0200 Original-Received: from localhost ([127.0.0.1]:41427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZ5Qq-0007Du-Nb for guile-devel@m.gmane.org; Thu, 06 Aug 2009 12:03:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MZ5Nc-00063o-I5 for guile-devel@gnu.org; Thu, 06 Aug 2009 11:59:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MZ5NX-000623-6d for guile-devel@gnu.org; Thu, 06 Aug 2009 11:59:47 -0400 Original-Received: from [199.232.76.173] (port=57810 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZ5NX-000620-0u for guile-devel@gnu.org; Thu, 06 Aug 2009 11:59:43 -0400 Original-Received: from a-sasl-quonix.sasl.smtp.pobox.com ([208.72.237.25]:64430 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MZ5NW-00038M-8P for guile-devel@gnu.org; Thu, 06 Aug 2009 11:59:42 -0400 Original-Received: from localhost.localdomain (unknown [127.0.0.1]) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTP id 55E7C23140; Thu, 6 Aug 2009 11:59:39 -0400 (EDT) Original-Received: from unquote (unknown [82.123.117.215]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTPSA id DD4E02313F; Thu, 6 Aug 2009 11:59:33 -0400 (EDT) In-Reply-To: (Andy Wingo's message of "Wed, 05 Aug 2009 12:42:25 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: 2583E8C8-82A2-11DE-A21B-F699A5B33865-02397024!a-sasl-quonix.pobox.com X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9035 Archived-At: Hi, On Wed 05 Aug 2009 12:42, Andy Wingo writes: > The simple stack formulation of Ackermann's function is faster of > course: > > (define (A m n) > (if (= m 0) > (+ n 1) > (if (= n 0) > (A (- m 1) 1) > (A (- m 1) (A m (- n 1)))))) > > (A 3 9) completes in 1.45 seconds for me. > > Curiously, the letrec case takes more time: > > (define (A m n) > (let A ((m m) (n n)) > (if (= m 0) > (+ n 1) > (if (= n 0) > (A (- m 1) 1) > (A (- m 1) (A m (- n 1))))))) > > It should be faster, because we don't have to deref the toplevel > variable for A, but the compiler needs to be a little smarter. This > version takes about 1.6 seconds for me. I have fixed this issue. The letrec version now takes slightly less time than the version that recurses through the toplevel. >> % time guile -c '(begin (load-compiled "ack.go") (ackermann 3 9))' >> 48.728u 22.016s 1:10.75 99.9% 0+0k 0+0io 0pf+0w > > Indeed, I get similar times (44 seconds; presumably some of the > compilation fixes actually had an effect). This one now takes very, very marginally less time now (about a second) -- not much of an improvement, but I wanted to take care of it before taking catch / dynamic-wind. Thanks, Andy -- http://wingolog.org/