Hello all:<br><br>I want to generate some hamming distance statistics about a set of strings. <br>As explained in another e-mail in this list, I used the following code to call the<br>functions:<br>(exampl holds the list of strings of size w)<br>
filter (\x -&gt; x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs &lt;- exampl, ys &lt;- exampl]<br><br>I have two hamming functions:<br>-- hamming distance for variable length strings<br>hamming :: String -&gt; String -&gt; Int<br>
hamming x y = hamming&#39; x y 0<br>    where       <br>      hamming&#39; [] _ !c = c<br>      hamming&#39; _ [] !c = c<br>      hamming&#39; (x:xs) (y:ys) !c <br>          | x == y = hamming&#39; xs ys c<br>          | otherwise = hamming&#39; xs ys (c + 1)<br>
<br>-- function posted in this mailing list<br>hamming2 :: String -&gt; String -&gt; Int<br>hamming2 xs ys = length (filter not (zipWith (==) xs ys))<br><br>I am executing these functions millions of times and the bottleneck of my program is in them as explained by running in profiling mode with  +RTS -K400M -p -RTS<br>
<br>The costlier function is the hamming distance<br>COST CENTRE                    MODULE               %time %alloc<br><br>hamming                        Distances             66.6   41.9<br><br>It says that it is performing 41% of the allocations. In the case of hamming2 the allocations go as far as 52%.  I could understand that there are allocations in &quot;hamming2&quot; because we are creating pairs, but in the case of &quot;hamming&quot; there should be no allocation.<br>
<br>How can I execute my hamming functions without allocating memory?<br><br>Best regards,<br><br>Arnoldo Muller<br><br>