Commits

Bryan O'Sullivan committed 4516b5b

Beginnings of a benchmark suite.

  • Participants
  • Parent commits 7ec7775

Comments (0)

Files changed (4)

 \.(?:aux|eventlog|h[ip]|hs.html|log|[mt]ix|[oa]|orig|prof|ps|rej|swp)$
 ~$
 benchmarks/Arse
+benchmarks/dist
 benchmarks/med.txt
 benchmarks/tiny
 hpc.*\.html$

File attoparsec.cabal

     file formats.
 extra-source-files:
     README.markdown
+    benchmarks/Benchmarks.hs
     benchmarks/Makefile
     benchmarks/Tiny.hs
+    benchmarks/attoparsec-benchmarks.cabal
     benchmarks/med.txt.bz2
     tests/Makefile
     tests/QC.hs

File benchmarks/Benchmarks.hs

+{-# LANGUAGE BangPatterns #-}
+
+import Control.Applicative
+import Criterion.Main (bench, bgroup, defaultMain, nf, whnf)
+import Data.Char
+import qualified Data.Attoparsec.ByteString as AB
+import qualified Data.Attoparsec.ByteString.Char8 as AC
+import qualified Data.Attoparsec.Text as AT
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as BC
+import qualified Data.Text as T
+import qualified Text.Parsec as P
+import qualified Text.Parsec.Text as P
+import Control.DeepSeq (NFData(rnf))
+import Data.ByteString.Internal (ByteString(..))
+
+instance NFData ByteString where
+    rnf (PS _ _ _) = ()
+
+instance NFData P.ParseError where
+    rnf = rnf . show
+
+main = do
+  let s  = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']
+      !b = BC.pack s
+      !t = T.pack s
+  defaultMain [
+     bgroup "comparison" [
+       bgroup "parsec-vs-atto" [
+         bench "attoparsec B" $ whnf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
+       , bench "attoparsec T" $ whnf (AT.parse (many (AT.satisfy AC.isAlpha_ascii))) t
+       , bench "parsec B" $ whnf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") b
+       , bench "parsec S" $ whnf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") s
+       , bench "parsec T" $ whnf (P.parse (many (P.satisfy AC.isAlpha_ascii)) "") t
+       ]
+     , bgroup "many-vs-takeWhile" [
+         bench "many" $ whnf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
+       , bench "takeWhile" $ whnf (AB.parse (AC.takeWhile AC.isAlpha_ascii)) b
+       ]
+     , bgroup "letter-vs-many" [
+         bench "letter" $ whnf (AB.parse (many AC.letter_ascii)) b
+       , bench "many" $ whnf (AB.parse (many (AC.satisfy AC.isAlpha_ascii))) b
+       ]
+     ]
+   , bgroup "takeWhile" [
+       bench "isAlpha" $ whnf (AB.parse (AC.takeWhile isAlpha)) b
+     , bench "isAlpha_ascii" $ whnf (AB.parse (AC.takeWhile AC.isAlpha_ascii)) b
+     , bench "isAlpha_iso8859_15" $ whnf (AB.parse (AC.takeWhile AC.isAlpha_iso8859_15)) b
+     ]
+   ]

File benchmarks/attoparsec-benchmarks.cabal

+-- These benchmarks are not intended to be installed.
+-- So don't install 'em.
+
+name: attoparsec-benchmarks
+version: 0
+cabal-version: >=1.2
+build-type: Simple
+
+executable attoparsec-benchmarks
+  main-is: Benchmarks.hs
+  build-depends:
+    attoparsec,
+    base,
+    bytestring,
+    criterion >= 0.5,
+    deepseq == 1.1.*,
+    parsec >= 3.1.2,
+    text