git.iko.soy/typeable/attoparsec
on master help sign in
Document the Alternative benchmark
commitccbb5266855cae816a129b6359333d014be43ded authorBryan O'Sullivan <bos@serpentine.com> dateTue 4 Mar 2014, 21:48 (13 years ago) parent70b0402
1 file changed+20
benchmarks/Alternative.hs+20
benchmarks/Alternative.hsnew file+20
@@ -0,0 +1,20 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+-- This benchmark reveals a huge performance regression that showed up
4+-- under GHC 7.8.1 (https://github.com/bos/attoparsec/issues/56).
5+--
6+-- With GHC 7.6.3 and older, this program runs in 0.04 seconds. Under
7+-- GHC 7.8.1 with (<|>) inlined, time jumps to 12 seconds!
8+
9+import Control.Applicative
10+import Data.Text (Text)
11+import qualified Data.Attoparsec.Text as A
12+import qualified Data.Text as T
13+
14+testParser :: Text -> Either String Int
15+testParser f = fmap length -- avoid printing out the entire matched list
16+ . A.parseOnly (many ((() <$ A.string "b") <|> (() <$ A.anyChar)))
17+ $ f
18+
19+main :: IO ()
20+main = print . testParser $ T.replicate 50000 "a"