Merge pull request #57 from Gabriel439/bench

Merge benchmark into master
This commit is contained in:
Index Int 2015-05-14 05:03:45 +03:00
commit afe4cd0f15
3 changed files with 55 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
dist
.cabal-sandbox
cabal.sandbox.config

40
bench/Main.hs Normal file
View file

@ -0,0 +1,40 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.Text as Text
import Criterion.Main
import Turtle
boundedNaive :: Int -> Int -> Pattern a -> Pattern [a]
boundedNaive m n p = do
x <- choice (map pure [m..n])
count x p
main :: IO ()
main = defaultMain
[ bgroup "Pattern"
[ let cats = Text.replicate 1000 "cat"
furniture = Text.replicate 5 " "
in bgroup "Cat Lady's House"
[ bench "Basic"
$ nf (match (many "cat")) cats
, bench "Letters"
$ nf (match (many (mconcat ["c", "a", "t"]))) cats
, bench "Spaces"
$ nf (match (many "cat" <* spaces)) (cats <> furniture)
, bench "Prefix"
$ nf (match (prefix (many "cat"))) (cats <> furniture)
]
, let hearts n = Text.replicate n "heart"
in bgroup "Love Knows No Bounds"
[ bench "500-700:650 Naive"
$ nf (match (boundedNaive 500 700 "heart")) (hearts 650)
, bench "500-700:650"
$ nf (match (bounded 500 700 "heart")) (hearts 650)
, bench "5000-7000:6500 Naive"
$ nf (match (boundedNaive 5000 7000 "heart")) (hearts 6500)
, bench "5000-7000:6500"
$ nf (match (bounded 5000 7000 "heart")) (hearts 6500)
]
]
]

View file

@ -82,3 +82,15 @@ test-suite tests
Build-Depends:
base >= 4 && < 5 ,
doctest >= 0.9.12 && < 0.10
benchmark bench
Type: exitcode-stdio-1.0
HS-Source-Dirs: bench
Main-Is: Main.hs
GHC-Options: -O2 -Wall -threaded
Default-Language: Haskell2010
Build-Depends:
base >= 4 && < 5 ,
criterion >= 1.1.0.0 && < 2 ,
text < 1.3,
turtle