unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Michael Ellis <michael.f.ellis@gmail.com>
To: Guile bug <bug-guile@gnu.org>
Subject: Loop optimization
Date: Mon, 7 Mar 2011 16:01:46 -0500	[thread overview]
Message-ID: <AANLkTikb5WuMAtBeqUpSZ_9H6hvaUuSOoQZjp_=3Thwd@mail.gmail.com> (raw)

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



             reply	other threads:[~2011-03-07 21:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-07 21:01 Michael Ellis [this message]
2011-03-07 21:36 ` Loop optimization Andy Wingo
2011-03-07 23:10   ` Michael Ellis
2011-03-08  0:28     ` Mark H Weaver
2011-03-08  0:30       ` Mark H Weaver
2011-03-08 21:43     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTikb5WuMAtBeqUpSZ_9H6hvaUuSOoQZjp_=3Thwd@mail.gmail.com' \
    --to=michael.f.ellis@gmail.com \
    --cc=bug-guile@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).