[Haskell-cafe] Slower with ByteStrings?

Donald Bruce Stewart dons at cse.unsw.edu.au
Mon May 28 20:43:54 EDT 2007


bulat.ziganshin:
> Hello Bryan,
> 
> Sunday, May 27, 2007, 3:30:50 AM, you wrote:
> >> I think, given my simple algorithm that means that (==) for
> >> ByteStrings is slower than (==) for String.  Is this possible?
> 
> > Yes indeed.  Over ByteStrings, (==) is implemented as a call to memcmp.
> >   For small strings, this loses by a large margin because it has to go
> > through the FFI.
> 
> how about using *unsafe* memcmp import and more complex code for the
> case of large BS length?
> 
> a==b | min (length a) (length b) < 20   = memcmp a b
>      ....
> 

Good idea. I'll try to do this before the next bytestring comes out .

-- Don


More information about the Haskell-Cafe mailing list