[Haskell-cafe] Seven ways to store 16 bytes

Mark Lentczner markl at glyphic.com
Tue Jan 5 19:06:09 EST 2010

In preparing the speed ups in uuid-0.1.2, I investigated various ways to store 16 bytes of data in a Haskell object.  Surprisingly, storing as 4 Word32 values in a standard data type worked best for that application.

I've extracted out the testing work for that and put it here:

There you can find the code that tests storing 16 bytes in various ways:

> import qualified Data.Array         as A
> import qualified Data.Array.Unboxed as U
> import qualified Data.Array.Vector  as V
> import qualified Data.ByteString    as B
> data InBytes = BY !Word8 !Word8 !Word8 !Word8 !Word8 !Word8 !Word8 !Word8
>                   !Word8 !Word8 !Word8 !Word8 !Word8 !Word8 !Word8 !Word8
>     deriving (Eq, Ord)
> data InWords = WO !Word32 !Word32 !Word32 !Word32
>     deriving (Eq, Ord)
> data InList       = LI [Word8]              deriving (Eq, Ord)
> data InByteString = BS B.ByteString         deriving (Eq, Ord)
> data InArray      = AR (A.Array Int Word8)  deriving (Eq, Ord)
> data InUArray     = UA (U.UArray Int Word8) deriving (Eq, Ord)
> data InVector     = VE (V.UArr Word8)       deriving (Eq)

Depending on operations will be needed most, different storage methods do best.


	- Mark 

Mark Lentczner (MtnViewMark)

More information about the Haskell-Cafe mailing list