@@ -20,6 +20,7 @@ module Benchmarks.DecodeUtf8
2020
2121import Foreign.C.Types
2222import Data.ByteString.Internal (ByteString(..))
23+import Data.ByteString.Lazy.Internal (ByteString(..))
2324import Foreign.Ptr (Ptr, plusPtr)
2425import Foreign.ForeignPtr (withForeignPtr)
2526import Data.Word (Word8)
@@ -38,8 +39,15 @@ benchmark kind fp = do
3839 bs <- B.readFile fp
3940 lbs <- BL.readFile fp
4041 let bench name = C.bench (name ++ "+" ++ kind)
42+ decodeStream (Chunk b0 bs0) = case T.streamDecodeUtf8 b0 of
43+ T.Some t0 _ f0 -> t0 : go f0 bs0
44+ where go f (Chunk b bs1) = case f b of
45+ T.Some t1 _ f1 -> t1 : go f1 bs1
46+ go _ _ = []
47+ decodeStream _ = []
4148 return $ bgroup "DecodeUtf8"
4249 [ bench "Strict" $ nf T.decodeUtf8 bs
50+ , bench "Stream" $ nf decodeStream lbs
4351 , bench "IConv" $ iconv bs
4452 , bench "StrictLength" $ nf (T.length . T.decodeUtf8) bs
4553 , bench "StrictInitLength" $ nf (T.length . T.init . T.decodeUtf8) bs
@@ -52,7 +60,7 @@ benchmark kind fp = do
5260 , bench "LazyStringUtf8Length" $ nf (length . U8.toString) lbs
5361 ]
5462
55−iconv :: ByteString -> IO CInt
63+iconv :: B.ByteString -> IO CInt
5664iconv (PS fp off len) = withForeignPtr fp $ \ptr ->
5765 time_iconv (ptr `plusPtr` off) (fromIntegral len)
5866