[Haskell-cafe] How to speed things up
Cale Gibbard
cgibbard at gmail.com
Thu Apr 28 11:35:29 EDT 2005
I'd use a Map in GHC 6.4:
count xs = toList $ fromListWith (+) (zip xs (repeat 1))
or a FiniteMap in earlier versions:
count xs = fmToList $ addListToFM_C (+) emptyFM (zip xs (repeat 1))
both of these seem to be quite fast.
- Cale
On 4/28/05, Dmitry Vyal <akamaus at gmail.com> wrote:
> Hello everybody.
>
> I have a long list consisted of a small number (about a dozen) of
> elements repeating in random pattern. I know all the possible elements.
> I need to count number of occurences of each particular element and to
> do i quickly.
>
> For example
> quick_func Eq a => [a] -> [(a,Int)]
> quick_func [1,2,3,1,2,9,1,9] == [(1,3),(2,2),(3,1),(9,2)]
>
> According to profiler this function is the bottle-neck in my sluggish
> program so I really need to speed it up.
>
> Any proposals?
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list