[Haskell-cafe] How to improve its performance ?

Alexander Solla ajs at 2piix.com
Wed Mar 17 21:24:45 EDT 2010


On Mar 17, 2010, at 6:14 PM, Daniel Fischer wrote:

> I found it surprisingly not-slow (code compiled with -O2, as usual).
> There are two points where you waste time.


I found one big point where time is wasted:  in computing the powerset  
of a list.  He's making 2^n elements, and then iterating through them  
all and filtering, but only needs n^2 or n `choose` 2 of the  
(depending on the semantics for his "groups").

The answer is to do something like:

allPairs list = [(x,y) | x <- list, y <- list]

to get it done in n^2 time.


More information about the Haskell-Cafe mailing list