1{-# LANGUAGE BangPatterns, CPP #-}
4import Control.Applicative (many)
5import Criterion.Main (bench, bgroup, defaultMain, nf)
7import Data.Char (isAlpha)
8import Data.Word (Word32)
9import Data.Word (Word8)
10import Numbers (numbers)
11import Common (chunksOf)
12import Text.Parsec.Text ()
13import Text.Parsec.Text.Lazy ()
16import qualified Genome
17import qualified Data.Attoparsec.ByteString as AB
18import qualified Data.Attoparsec.ByteString.Char8 as AC
19import qualified Data.Attoparsec.ByteString.Lazy as ABL
20import qualified Data.Attoparsec.Text as AT
21import qualified Data.Attoparsec.Text.Lazy as ATL
22import qualified Data.ByteString as B
23import qualified Data.ByteString.Char8 as BC
24import qualified Data.ByteString.Lazy as BL
25import qualified Data.Text as T
26import qualified Data.Text.Lazy as TL
27import qualified HeadersByteString
28import qualified HeadersText
30import qualified Text.Parsec as P
34 let s = take 1024 . cycle $ ['a'..'z'] ++ ['A'..'Z']
36 !bl = BL.fromChunks . map BC.pack . chunksOf 4 $ s
38 !tl = TL.fromChunks . map T.pack . chunksOf 4 $ s
40 headersBS <- HeadersByteString.headers
41 headersT <- HeadersText.headers
45 bench "B" $ nf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
46 , bench "BL" $ nf (ABL.parse (many (AC.satisfy AC.isAlpha_ascii))) bl
47 , bench "T" $ nf (AT.parse (many (AT.satisfy AC.isAlpha_ascii))) t
48 , bench "TL" $ nf (ATL.parse (many (AT.satisfy AC.isAlpha_ascii))) tl
51 bench "S" $ nf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") s
52 , bench "B" $ nf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") b
53 , bench "BL" $ nf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") bl
54 , bench "T" $ nf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") t
55 , bench "TL" $ nf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") tl
58 , bgroup "comparison" [
59 bgroup "many-vs-takeWhile" [
60 bench "many" $ nf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
61 , bench "takeWhile" $ nf (AB.parse (AC.takeWhile AC.isAlpha_ascii)) b
63 , bgroup "letter-vs-isAlpha" [
64 bench "letter" $ nf (AB.parse (many AC.letter_ascii)) b
65 , bench "isAlpha" $ nf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
68 , bgroup "takeWhile" [
69 bench "isAlpha" $ nf (ABL.parse (AC.takeWhile isAlpha)) bl
70 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_ascii)) bl
71 , bench "isAlpha_iso8859_15" $
72 nf (ABL.parse (AC.takeWhile AC.isAlpha_iso8859_15)) bl
74 , bgroup "takeWhile1" [
75 bench "isAlpha" $ nf (ABL.parse (AC.takeWhile1 isAlpha)) bl
76 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile1 AC.isAlpha_ascii)) bl
78 , bench "word32LE" $ nf (AB.parse word32LE) b
80 bench "short" $ nf (AB.parse quotedString) (BC.pack "abcdefghijk\"")
81 , bench "long" $ nf (AB.parse quotedString) b
92-- Benchmarks bind and (potential) bounds-check merging.
93word32LE :: AB.Parser Word32
99 return $! (fromIntegral w1 :: Word32) +
100 fromIntegral w2 `unsafeShiftL` 8 +
101 fromIntegral w3 `unsafeShiftL` 16 +
102 fromIntegral w4 `unsafeShiftL` 32
104doubleQuote, backslash :: Word8
107{-# INLINE backslash #-}
108{-# INLINE doubleQuote #-}
110-- | Parse a string without a leading quote.
111quotedString :: AB.Parser B.ByteString
112quotedString = AB.scan False $ \s c -> if s then Just False
113 else if c == doubleQuote
115 else Just (c == backslash)
117#if !MIN_VERSION_base(4,5,0)
118unsafeShiftL :: Bits a => a -> Int -> a
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list