[Haskell-cafe] Re: Write Haskell as fast as C.
Don Stewart
dons at galois.com
Fri May 16 17:59:33 EDT 2008
ketil:
> Andrew Coppin <andrewcoppin at btinternet.com> writes:
>
> > I'm more worried about what happens in less trivial examples. [Let's
> > face it, who wants to compute the sum of the numbers from 1 to N?]
>
> Inspired by Don's blog post, and coincidentally working on a program
> where profiling points to one particular, short function as
> responsible for 60% of the work, I thought this would be a good time
> to look into core and reveal the deep secrets of my code. This is the
> function:
>
> > mkAnn :: ByteString -> Annotation
> > mkAnn = pick . B.words
> > where pick (_db:up:rest) = pick' up $ getGo rest
> > pick' up' (go:_:ev:_) = Ann (B.copy up') (read $ B.unpack go) (read $ B.unpack ev)
> > getGo = dropWhile (not . B.isPrefixOf (pack "GO:"))
>
read $ B.unpack go
Looks suspicious. You're unpacking to lists.
ByteString performance rule 1: don't unpack to lists.
-- Don
More information about the Haskell-Cafe
mailing list