[Haskell-beginners] When to use ByteString rather than [Char] ...?
Daniel Fischer
daniel.is.fischer at web.de
Sun Apr 11 11:55:14 EDT 2010
Am Sonntag 11 April 2010 17:15:22 schrieb Stephen Tetley:
> On 11 April 2010 15:42, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> [SNIP]
>
> > When dealing with short strings, in my experience there are rarely
> > compelling reasons to choose one over the other.
>
> Hi Daniel
>
> Thanks - I was slightly surprised at the results in the paper because
> the 'cons' test for was equal, I thought bytestrings have to do a bit
> more work for a 'cons' - looking at the code lazy bytestring uses one
> constructor and a bit of C memory poking, which is the C memory poking
> more than I'd expect the [Char] version to do.
Well, I guess it depends on what actually happens with fusion (a single
cons doesn't take significant time for either). If repeated conses lead to
a chain of one-element chunks, I'd expect that to be significantly slower
than [Char], but if it's rewritten to
- allocate a new chunk,
- write from end and decrement offset counter,
it shouldn't be slower.
>
> The only 'determinant' I've found for choosing which type for short
> strings is if I'm using a library that forces one or the other on me,
Sure, that's pretty compelling - as long as you don't need two libraries
with different choices :)
> otherwise I'm swayed by the simplicity of [Char].
>
> Best wishes
>
> Stephen
More information about the Beginners
mailing list