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 -> x /= 0) $ map (uncurry hammingX) [(xs, ys) | xs <- exampl, ys <- exampl]<br><br>I have two hamming functions:<br>-- hamming distance for variable length strings<br>hamming :: String -> String -> Int<br>
hamming x y = hamming' x y 0<br> where <br> hamming' [] _ !c = c<br> hamming' _ [] !c = c<br> hamming' (x:xs) (y:ys) !c <br> | x == y = hamming' xs ys c<br> | otherwise = hamming' xs ys (c + 1)<br>
<br>-- function posted in this mailing list<br>hamming2 :: String -> String -> 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 "hamming2" because we are creating pairs, but in the case of "hamming" 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>