Competing with C in a simple loop

Erik de Castro Lopo mle+hs at
Thu Dec 22 22:43:51 UTC 2016

Christopher Done wrote:

> But if you scroll down the README to the 182kb file example, you see that
> hexml takes 33us and xeno takes 111us. That's surprising to me because I'm
> doing just a walk across a string and hexml is doing a full parse. It's
> written in C, but still, 3x faster AND doing allocations and more work.
> I tried replacing the ByteString with a raw Ptr Word8 and it didn't make a
> difference, actually increased time a little bit.

The code you have written still looks like Haskell code. When I write Haskell
code that needs to compete speedwise with C, it usually ends up looking like
C as well. My suggestion is to drop `Data.ByteString.elemIndex` in favour of
direct unsafe array accesses.

If I find a bit of time over the next couple of days I might have a crack at

Erik de Castro Lopo

More information about the ghc-devs mailing list