git.iko.soy/typeable/attoparsec
on master help sign in
typeable/attoparsec/benchmarks/HeadersByteString.hs
37 lines 1.5 kB history raw
1module HeadersByteString (headers) where
3import Common (pathTo, rechunkBS)
4import Criterion.Main (bench, bgroup, nf, nfIO)
5import Criterion.Types (Benchmark)
6import HeadersByteString.Atto (request, response)
7import Network.Wai.Handler.Warp.RequestHeader (parseHeaderLines)
8import qualified Data.Attoparsec.ByteString.Char8 as B
9import qualified Data.Attoparsec.ByteString.Lazy as BL
10import qualified Data.ByteString.Char8 as B
12-- Note: In the benchmarks for parsing an http request
13-- from a strict bytestring, we consider warp's implementation,
14-- which has highly optimized code for handling the first
15-- line in particular. It's treatment of the headers
16-- is more relaxed from the treatment they are given by the
17-- attoparsec parser benchmarked here. Consequently, it
18-- is should not be possible to match its performance since
19-- it accepts header names with disallowed characters.
21headers :: IO Benchmark
22headers = do
23 req <- B.readFile =<< pathTo "http-request.txt"
24 resp <- B.readFile =<< pathTo "http-response.txt"
25 let reql = rechunkBS 4 req
26 respl = rechunkBS 4 resp
27 return $ bgroup "headers" [
28 bgroup "B" [
29 bench "request" $ nf (B.parseOnly request) req
30 , bench "warp" $ nfIO (parseHeaderLines (B.split '\n' req))
31 , bench "response" $ nf (B.parseOnly response) resp
32 ]
33 , bgroup "BL" [
34 bench "request" $ nf (BL.parse request) reql
35 , bench "response" $ nf (BL.parse response) respl
36 ]
37 ]