<br><br><div class="gmail_quote">On Fri, Sep 3, 2010 at 21:43, bearophile <span dir="ltr">&lt;<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Don:<br>
<div class="im">&gt; That&#39;s not a very useful problem, because the timing depends entirely on<br>
&gt; BigInt, which is completely unoptimised for small values.<br>
<br>
</div>You are usually right, but this time what you say is useless. There are other means to judge how good a program is, beside running time:<br>
- Total line count of the program;<br>
- Max amount of memory used.<br>
<br>
The Haskell version of the program is quite fast, very short, and it&#39;s lazy so it uses very low memory.</blockquote><div><br>It&#39;s crystal clear &amp; short (but we should aim for J! :-), but being lazy I don&#39;t see how it can use less memory than a strict version of the same algo. Got to store all those thunks somewhere.<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> The &quot;Alternate version using &quot;Cyclic Iterators&quot;&quot; Python version invented by the great Raymond Hettinger too is lazy and uses very low memory. On the other hand, that D version, that I have translated from the Java code, is eager so it uses a lot of memory, is slow (mostly because of the bigint implementation, I agree), and its source is many lines long. So D must do better along one or more than one of those axis.<font color="#888888"><br>
</font></blockquote><div><br>What did you use to compare them? (out of curiosity, not attack).<br>I used GHCi, and got 8.8s for the millionth Hamming number, using ~450 Mo of RAM, according to GHCi itself (:set +s, :set +t). But I&#39;m no pro in optimizing Haskell compilation.<br>
For my own D version, that is quite near the Rosetta Code version, I get 3.7s, 100 Mo of RAM. (-O -release -inline)<br>Using the RC code (your own, translated from Java, right?), I get the same. Same result, same time, same memory consumption. Yeah, my code is not wrong :-)<br>
So, at least naively like this for me, D is more than twice as fast as Haskell and uses about 80% less memory.<br><br>Of course, GHC caches results, so the second time I ask for the millionth Hamming number, I get it almost instantaneously. Nifty, that!<br>
<br><br>Philippe<br></div></div><br>