Skip to content

Instantly share code, notes, and snippets.

@hvr
Created March 3, 2012 08:50
Show Gist options
  • Save hvr/1965035 to your computer and use it in GitHub Desktop.
Save hvr/1965035 to your computer and use it in GitHub Desktop.
module Main where
import Control.DeepSeq
import Control.Exception (evaluate)
import Criterion.Main
import qualified Data.ByteString.Char8 as B
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.ICU.Convert as TI
test7bit_0 = B.empty
test7bit_16 = B.pack $ take 16 $ cycle ['\0' .. '\x7f']
test7bit_1K = B.pack $ take (1024) $ cycle ['\0' .. '\x7f']
test7bit_1M = B.pack $ take (1024*1024) $ cycle ['\0' .. '\x7f']
decodeL1 = T.pack . B.unpack
ttest7bit_0 = decodeL1 test7bit_0
ttest7bit_16 = decodeL1 test7bit_16
ttest7bit_1K = decodeL1 test7bit_1K
ttest7bit_1M = decodeL1 test7bit_1M
instance NFData B.ByteString
main :: IO ()
main = do
cvtL1 <- TI.open "ISO-8859-1" Nothing
cvtUtf8 <- TI.open "UTF8" Nothing
let decodeIcuL1 = TI.toUnicode cvtL1
decodeIcuUtf8 = TI.toUnicode cvtUtf8
evaluate $ rnf [ test7bit_0, test7bit_16, test7bit_1K, test7bit_1M ]
evaluate $ rnf [ ttest7bit_0, ttest7bit_16, ttest7bit_1K, ttest7bit_1M ]
defaultMain
[ bgroup "id" [ bench "0" $ nf id ttest7bit_0
, bench "16" $ nf id ttest7bit_16
, bench "1K" $ nf id ttest7bit_1K
-- , bench "1M" $ nf id ttest7bit_1M
]
, bgroup "decodeIcuUtf8" [ bench "0" $ nf decodeIcuUtf8 test7bit_0
, bench "16" $ nf decodeIcuUtf8 test7bit_16
, bench "1K" $ nf decodeIcuUtf8 test7bit_1K
-- , bench "1M" $ nf decodeIcuUtf8 test7bit_1M
]
, bgroup "TE.decodeUtf8" [ bench "0" $ nf TE.decodeUtf8 test7bit_0
, bench "16" $ nf TE.decodeUtf8 test7bit_16
, bench "1K" $ nf TE.decodeUtf8 test7bit_1K
-- , bench "1M" $ nf TE.decodeUtf8 test7bit_1M
]
, bgroup "TE.decodeLatin1" [ bench "0" $ nf TE.decodeLatin1 test7bit_0
, bench "16" $ nf TE.decodeLatin1 test7bit_16
, bench "1K" $ nf TE.decodeLatin1 test7bit_1K
-- , bench "1M" $ nf TE.decodeLatin1 test7bit_1M
]
, bgroup "decodeIcuL1" [ bench "0" $ nf decodeIcuL1 test7bit_0
, bench "16" $ nf decodeIcuL1 test7bit_16
, bench "1K" $ nf decodeIcuL1 test7bit_1K
-- , bench "1M" $ nf decodeIcuL1 test7bit_1M
]
-- , bgroup "decodeL1(naive)" [ bench "0" $ nf decodeL1 test7bit_0
-- , bench "16" $ nf decodeL1 test7bit_16
-- , bench "1K" $ nf decodeL1 test7bit_1K
-- , bench "1M" $ nf decodeL1 test7bit_1M
-- ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment