git.iko.soy/typeable/html-parse
on dd116a6 help sign in
typeable/html-parse/Microbench.hs
33 lines 1.0 kB history raw
1{-# LANGUAGE MagicHash #-}
2{-# LANGUAGE OverloadedStrings #-}
4import GHC.Exts
5import Data.Char
6import qualified Data.Text as T
7import Data.Attoparsec.Text
8import Criterion.Main
9import Prelude hiding (take, takeWhile)
11isAsciiAlpha1 :: Char -> Bool
12isAsciiAlpha1 c = isAsciiLower c || isAsciiUpper c
14isAsciiAlpha2 :: Char -> Bool
15isAsciiAlpha2 (C# c) =
16 tagToEnum# ( ((c `geChar#` 'A'#) `andI#` (c `leChar#` 'Z'#))
17 `orI#` ((c `geChar#` 'a'#) `andI#` (c `leChar#` 'z'#)) )
19main :: IO ()
20main = defaultMain
21 [ bench "Text isAsciiAlpha1"
22 $ whnf (T.length . T.takeWhile isAsciiAlpha1) testString
23 , bench "Text isAsciiAlpha2"
24 $ whnf (T.length . T.takeWhile isAsciiAlpha2) testString
26 , bench "Attoparsec isAsciiAlpha1"
27 $ whnf (parseOnly (T.length <$> takeWhile isAsciiAlpha1)) testString
28 , bench "Attoparsec isAsciiAlpha2"
29 $ whnf (parseOnly (T.length <$> takeWhile isAsciiAlpha2)) testString
30 ]
32testString :: T.Text
33testString = T.replicate 10 "helloworldthisisarelativelylongstring"