@@ -1,3 +1,5 @@
1+{-# LANGUAGE ForeignFunctionInterface #-}
1-- | Test decoding of UTF-8
3-- | Test decoding of UTF-8
3-- Tested in this benchmark:
5-- Tested in this benchmark:
@@ -16,6 +18,11 @@ module Data.Text.Benchmarks.DecodeUtf8
16 ( benchmark
18 ( benchmark
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)
19import Criterion (Benchmark, bgroup, bench, nf)
26import Criterion (Benchmark, bgroup, bench, nf)
20import qualified Codec.Binary.UTF8.Generic as U8
27import qualified Codec.Binary.UTF8.Generic as U8
21import qualified Data.ByteString as B
28import qualified Data.ByteString as B
@@ -31,6 +38,7 @@ benchmark fp = do
31 lbs <- BL.readFile fp
38 lbs <- BL.readFile fp
32 return $ bgroup "DecodeUtf8"
39 return $ bgroup "DecodeUtf8"
33 [ bench "Strict" $ nf T.decodeUtf8 bs
40 [ bench "Strict" $ nf T.decodeUtf8 bs
41+ , bench "IConv" $ iconv bs
34 , bench "StrictLength" $ nf (T.length . T.decodeUtf8) bs
42 , bench "StrictLength" $ nf (T.length . T.decodeUtf8) bs
35 , bench "StrictInitLength" $ nf (T.length . T.init . T.decodeUtf8) bs
43 , bench "StrictInitLength" $ nf (T.length . T.init . T.decodeUtf8) bs
36 , bench "Lazy" $ nf TL.decodeUtf8 lbs
44 , bench "Lazy" $ nf TL.decodeUtf8 lbs
@@ -41,3 +49,9 @@ benchmark fp = do
41 , bench "LazyStringUtf8" $ nf U8.toString lbs
49 , bench "LazyStringUtf8" $ nf U8.toString lbs
42 , bench "LazyStringUtf8Length" $ nf (length . U8.toString) lbs
50 , bench "LazyStringUtf8Length" $ nf (length . U8.toString) lbs
53+iconv :: ByteString -> IO CInt
54+iconv (PS fp off len) = withForeignPtr fp $ \ptr ->
55+ time_iconv (ptr `plusPtr` off) (fromIntegral len)
57+foreign import ccall unsafe time_iconv :: Ptr Word8 -> CSize -> IO CInt