[Haskell-cafe] Re: Shootout summary
Matthias Neubauer
neubauer at informatik.uni-freiburg.de
Sat Jan 7 04:36:01 EST 2006
dons at cse.unsw.edu.au (Donald Bruce Stewart) writes:
>> > Fannkuch entry by Bertram Felgenhauer
>> > Mandelbrot entry
>>
>> I've done some benchmarking of the current entries for fannkuch and
>> mandelbrot, and have proposed final entries for these two tests.
Using >>= of the list monad in the current Fannkuch proposal
(permutations) hides some costly ++ applications that can be also
optimized away:
Instead of writting
permutations l = foldr perm' [l] [2..length l]
where perm' n l = l >>= take n . iterate (rotate n)
saying something like
permutations l = foldr perm' [l] [2..length l]
perm' n = foldr (takeIter n (rotate n)) []
takeIter :: Int -> (a -> a) -> a -> [a] -> [a]
takeIter 0 f x rest = rest
takeIter n f x rest = x : takeIter (n-1) f (f x) rest
gains us another 5% or so.
-Matthias
--
Matthias Neubauer |
Universität Freiburg, Institut für Informatik | tel +49 761 203 8060
Georges-Köhler-Allee 79, 79110 Freiburg i. Br., Germany | fax +49 761 203 8052
More information about the Haskell-Cafe
mailing list