[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Loop optimization
From: |
Michael Ellis |
Subject: |
Loop optimization |
Date: |
Mon, 7 Mar 2011 16:01:46 -0500 |
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
- Loop optimization,
Michael Ellis <=