git.iko.soy/typeable/attoparsec
on master help sign in
Merge new benchmarks from 0.11
05fc26cBryan O'Sullivan
benchmarks/Benchmarks.hs+1
@@ -1,5 +1,6 @@
1{-# LANGUAGE BangPatterns, CPP #-}
1{-# LANGUAGE BangPatterns, CPP #-}
2
2
3+import Common ()
3import Control.Applicative (many)
4import Control.Applicative (many)
4import Criterion.Main (bench, bgroup, defaultMain, nf)
5import Criterion.Main (bench, bgroup, defaultMain, nf)
5import Data.Bits
6import Data.Bits
benchmarks/Common.hs+15−1
@@ -1,10 +1,18 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3
3
4−module Common (chunksOf) where
4+module Common (
5+ chunksOf
6+ , rechunkBS
7+ , rechunkT
8+ ) where
5
9
6import Control.DeepSeq (NFData(rnf))
10import Control.DeepSeq (NFData(rnf))
7import Text.Parsec (ParseError)
11import Text.Parsec (ParseError)
12+import qualified Data.ByteString as B
13+import qualified Data.ByteString.Lazy as BL
14+import qualified Data.Text as T
15+import qualified Data.Text.Lazy as TL
8
16
9#if !MIN_VERSION_bytestring(0,10,0)
17#if !MIN_VERSION_bytestring(0,10,0)
10import Data.ByteString.Internal (ByteString(..))
18import Data.ByteString.Internal (ByteString(..))
@@ -21,3 +29,9 @@ chunksOf k = go
21 where go xs = case splitAt k xs of
29 where go xs = case splitAt k xs of
22 ([],_) -> []
30 ([],_) -> []
23 (y, ys) -> y : go ys
31 (y, ys) -> y : go ys
32+
33+rechunkBS :: Int -> B.ByteString -> BL.ByteString
34+rechunkBS n = BL.fromChunks . map B.pack . chunksOf n . B.unpack
35+
36+rechunkT :: Int -> T.Text -> TL.Text
37+rechunkT n = TL.fromChunks . map T.pack . chunksOf n . T.unpack
benchmarks/HeadersByteString.hs+13−4
@@ -2,11 +2,12 @@
2{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
3module HeadersByteString (headers) where
3module HeadersByteString (headers) where
4
4
5−import Common ()
5+import Common (rechunkBS)
6import Control.Applicative
6import Control.Applicative
7import Criterion.Main (bench, bgroup, nf)
7import Criterion.Main (bench, bgroup, nf)
8import Criterion.Types (Benchmark)
8import Criterion.Types (Benchmark)
9import qualified Data.Attoparsec.ByteString.Char8 as B
9import qualified Data.Attoparsec.ByteString.Char8 as B
10+import qualified Data.Attoparsec.ByteString.Lazy as BL
10import qualified Data.ByteString.Char8 as B
11import qualified Data.ByteString.Char8 as B
11
12
12header = do
13header = do
@@ -41,7 +42,15 @@ headers :: IO Benchmark
41headers = do
42headers = do
42 req <- B.readFile "http-request.txt"
43 req <- B.readFile "http-request.txt"
43 resp <- B.readFile "http-response.txt"
44 resp <- B.readFile "http-response.txt"
45+ let reql = rechunkBS 4 req
46+ respl = rechunkBS 4 resp
44− return $ bgroup "headersBS" [
47+ return $ bgroup "headers" [
48+ bgroup "B" [
45− bench "request" $ nf (B.parseOnly request) req
49+ bench "request" $ nf (B.parseOnly request) req
46− , bench "response" $ nf (B.parseOnly response) resp
50+ , bench "response" $ nf (B.parseOnly response) resp
51+ ]
52+ , bgroup "BL" [
53+ bench "request" $ nf (BL.parse request) reql
54+ , bench "response" $ nf (BL.parse response) respl
55+ ]
47 ]
56 ]
benchmarks/HeadersText.hs+13−3
@@ -2,11 +2,13 @@
2{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
3module HeadersText (headers) where
3module HeadersText (headers) where
4
4
5+import Common (rechunkT)
5import Control.Applicative
6import Control.Applicative
6import Criterion.Main (bench, bgroup, nf)
7import Criterion.Main (bench, bgroup, nf)
7import Criterion.Types (Benchmark)
8import Criterion.Types (Benchmark)
8import Data.Char (isSpace)
9import Data.Char (isSpace)
9import qualified Data.Attoparsec.Text as T
10import qualified Data.Attoparsec.Text as T
11+import qualified Data.Attoparsec.Text.Lazy as TL
10import qualified Data.Text.IO as T
12import qualified Data.Text.IO as T
11
13
12header = do
14header = do
@@ -41,7 +43,15 @@ headers :: IO Benchmark
41headers = do
43headers = do
42 req <- T.readFile "http-request.txt"
44 req <- T.readFile "http-request.txt"
43 resp <- T.readFile "http-response.txt"
45 resp <- T.readFile "http-response.txt"
46+ let reql = rechunkT 4 req
47+ respl = rechunkT 4 resp
44− return $ bgroup "headersT" [
48+ return $ bgroup "headers" [
49+ bgroup "T" [
45− bench "request" $ nf (T.parseOnly request) req
50+ bench "request" $ nf (T.parseOnly request) req
46− , bench "response" $ nf (T.parseOnly response) resp
51+ , bench "response" $ nf (T.parseOnly response) resp
52+ ]
53+ , bgroup "TL" [
54+ bench "request" $ nf (TL.parse request) reql
55+ , bench "response" $ nf (TL.parse response) respl
56+ ]
47 ]
57 ]