Benchmark the bounded combinator

This commit is contained in:
Index Int 2015-05-12 23:46:02 +03:00
parent be761a53f1
commit dc35a336d5

View file

@ -5,6 +5,11 @@ import qualified Data.Text as Text
import Criterion.Main import Criterion.Main
import Turtle 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 :: IO ()
main = defaultMain main = defaultMain
[ bgroup "Pattern" [ bgroup "Pattern"
@ -20,5 +25,16 @@ main = defaultMain
, bench "Prefix" , bench "Prefix"
$ nf (match (prefix (many "cat"))) (cats <> furniture) $ 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)
]
] ]
] ]