<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 9, 2013 at 2:42 PM, Matthew Flatt <span dir="ltr">&lt;<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">  (for/product ([p (in-range (+ m 1) (+ n 1))]) p)</blockquote></div><br><br></div><div class="gmail_extra">

This fact/for variant is a clear winner:<br>&gt; (time (void (fact/for 1000000)))<br>cpu time: 6948 real time: 6956 gc time: 964<br>&gt; (time (void (factorial 1000000)))<br>cpu time: 9936 real time: 9951 gc time: 3700<br>

&gt; (time (void (fact 1000000)))<br>cpu time: 8445 real time: 8460 gc time: 2273<br><br></div><div class="gmail_extra">But I don&#39;t fully understand  why a simple (for/product ([p (in-range 1 (add1 n))]) p) is as fast as the iota variants.<br>

</div><div class="gmail_extra">I see that the latter makes many more small products, which are certainly faster, but it also does more products of 2 big numbers, whereas for/product makes only big*small products. Is that a sufficient reason?<br>

<br></div><div class="gmail_extra">Laurent<br></div><div class="gmail_extra"><br></div></div>