git.iko.soy/typeable/attoparsec
on master help sign in
Change character predicate to not use inClass. Add note about the impossibility of matching the performance of warp.
commit6e2dc20db0cb57973fd092d35cfc4c8798bd37b2 authorAndrew Martin <andrew.thaddeus@gmail.com> dateMon 19 Mar 2018, 20:48 (9 years ago) parentfede5d1
2 files changed+18−1
benchmarks/HeadersByteString.hs+9 benchmarks/HeadersByteString/Atto.hs+9−1
benchmarks/HeadersByteString.hs+9
@@ -9,6 +9,15 @@ import qualified Data.Attoparsec.ByteString.Char8 as B
99import qualified Data.Attoparsec.ByteString.Lazy as BL
1010import qualified Data.ByteString.Char8 as B
1111
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.
20+
1221headers :: IO Benchmark
1322headers = do
1423 req <- B.readFile =<< pathTo "http-request.txt"
benchmarks/HeadersByteString/Atto.hs+9−1
@@ -15,8 +15,16 @@ import qualified Data.ByteString.Char8 as B
1515instance NFData HttpVersion where
1616 rnf !_ = ()
1717
18+isHeaderChar :: Char -> Bool
19+isHeaderChar c =
20+ (c >= 'a' && c <= 'z') ||
21+ (c >= 'A' && c <= 'Z') ||
22+ (c >= '0' && c <= '9') ||
23+ (c == '_') ||
24+ (c == '-')
25+
1826header = do
19− name <- B.takeWhile1 (B.inClass "a-zA-Z0-9_-") <* B.char ':' <* B.skipSpace
27+ name <- B.takeWhile1 isHeaderChar <* B.char ':' <* B.skipSpace
2028 body <- bodyLine
2129 return (name, body)
2230