@@ -1,3 +1,5 @@
1+{-# LANGUAGE ForeignFunctionInterface #-}
2+
13-- | Test decoding of UTF-8
24--
35-- Tested in this benchmark:
@@ -16,6 +18,11 @@ module Data.Text.Benchmarks.DecodeUtf8
1618 ( benchmark
1719 ) where
1820
21+import Foreign.C.Types (CInt, CSize)
22+import Data.ByteString.Internal (ByteString(..))
23+import Foreign.Ptr (Ptr, plusPtr)
24+import Foreign.ForeignPtr (withForeignPtr)
25+import Data.Word (Word8)
1926import Criterion (Benchmark, bgroup, bench, nf)
2027import qualified Codec.Binary.UTF8.Generic as U8
2128import qualified Data.ByteString as B
@@ -31,6 +38,7 @@ benchmark fp = do
3138 lbs <- BL.readFile fp
3239 return $ bgroup "DecodeUtf8"
3340 [ bench "Strict" $ nf T.decodeUtf8 bs
41+ , bench "IConv" $ iconv bs
3442 , bench "StrictLength" $ nf (T.length . T.decodeUtf8) bs
3543 , bench "StrictInitLength" $ nf (T.length . T.init . T.decodeUtf8) bs
3644 , bench "Lazy" $ nf TL.decodeUtf8 lbs
@@ -41,3 +49,9 @@ benchmark fp = do
4149 , bench "LazyStringUtf8" $ nf U8.toString lbs
4250 , bench "LazyStringUtf8Length" $ nf (length . U8.toString) lbs
4351 ]
52+
53+iconv :: ByteString -> IO CInt
54+iconv (PS fp off len) = withForeignPtr fp $ \ptr ->
55+ time_iconv (ptr `plusPtr` off) (fromIntegral len)
56+
57+foreign import ccall unsafe time_iconv :: Ptr Word8 -> CSize -> IO CInt