From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Ellis Newsgroups: gmane.lisp.guile.bugs Subject: Loop optimization Date: Mon, 7 Mar 2011 16:01:46 -0500 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1299532011 3577 80.91.229.12 (7 Mar 2011 21:06:51 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 7 Mar 2011 21:06:51 +0000 (UTC) To: Guile bug Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Mar 07 22:06:46 2011 Return-path: Envelope-to: guile-bugs@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 1PwhdU-0004Mi-VM for guile-bugs@m.gmane.org; Mon, 07 Mar 2011 22:06:46 +0100 Original-Received: from localhost ([127.0.0.1]:35963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwhZ5-0002WK-Tv for guile-bugs@m.gmane.org; Mon, 07 Mar 2011 16:02:03 -0500 Original-Received: from [140.186.70.92] (port=52775 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwhYu-0002Sf-4B for bug-guile@gnu.org; Mon, 07 Mar 2011 16:01:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwhYq-0000bW-1h for bug-guile@gnu.org; Mon, 07 Mar 2011 16:01:49 -0500 Original-Received: from mail-wy0-f169.google.com ([74.125.82.169]:61113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwhYp-0000bQ-T4 for bug-guile@gnu.org; Mon, 07 Mar 2011 16:01:48 -0500 Original-Received: by wyi11 with SMTP id 11so5296861wyi.0 for ; Mon, 07 Mar 2011 13:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=S7Vj5pVZgvINWDUWua7PN4XsFlYCWV6z8CSI0RnROJo=; b=E6gMlH/9aUGKZF5CKQHFxlgb6MPlLLd7Qwfv3XUkzQVDd0OsSPtUr2sMUYxShp2IL8 uUd/hwCdNID6Ne+POVFCpLIAmGJVLk8PGNio1fMvEGSnIvKlZAl9SZBzvWFbKkiFaSUQ ZCKVDw8QHvsKZLHn2WpVSQN7/xUQFSAIB4Ms0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=kW3GTOBpY8++GORJGXb0YyEp7ikHUi9/j+BOZ6pU8Fy/lHsARLFafO9I6apHwcJ/Oo Euc3SXz7VHLUMdTy96BqR2pm8aVs1v6AY8oboHKxhOvF/pHTtpctE1H+ChCObwVO+HLY jPTCVwrqWErRfCdefHLMGEcVWx3q/2zUhJRks= Original-Received: by 10.227.0.140 with SMTP id 12mr3957165wbb.122.1299531706259; Mon, 07 Mar 2011 13:01:46 -0800 (PST) Original-Received: by 10.227.144.207 with HTTP; Mon, 7 Mar 2011 13:01:46 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.169 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5304 Archived-At: I got a curious result while doing some really brain-dead performance comparisons between guile and python. All times are post-compilation. ------ guile ---------------- (let loop ((i 0) (j 1e7)) (set! i (+ i 1)) (if (< j i) (begin (display i) (newline)) (loop i j))) real 0m1.182s user 0m1.150s sys 0m0.015s ------ python ------------ i=0 j=int(1e7) while j > i: i += 1 print i real 0m1.943s user 0m1.915s sys 0m0.015s ----------------------------- So, congrats! Guile 2.0 is noticeably faster here (I can make python win by using "for i in xrange()" but that's not the point of this post.) What surprised me was that using a constant in the "if" test slows guile down by a factor 8. (let loop ((i 0)) (set! i (+ i 1)) (if (< 1e7 i) (begin (display i) (newline)) (loop i))) real 0m8.976s user 0m8.789s sys 0m0.035s Is this an expected outcome? I was naively supposing that compilation would be more effective at optimizing when the limit was a constant instead of a variable. I'm running OS X 10.6.6 on a 2.4GHz Intel Core Duo MacBook. Cheers, Mike