unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Loop optimization
@ 2011-03-07 21:01 Michael Ellis
  2011-03-07 21:36 ` Andy Wingo
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Ellis @ 2011-03-07 21:01 UTC (permalink / raw)
  To: Guile bug

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-08 21:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-07 21:01 Loop optimization Michael Ellis
2011-03-07 21:36 ` 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

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).