-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBenchmark.hs
29 lines (27 loc) · 1.16 KB
/
Benchmark.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Criterion.Main
import qualified Data.Text.IO as TIO
import Control.DeepSeq
import qualified Text.HTML.TagSoup as Soup
import qualified Text.HTML.Parser as Me
main :: IO ()
main = do
t <- TIO.readFile "test.html"
defaultMain
[ bgroup "Forced"
[ bench "tagsoup fast Text" $ nf (Soup.parseTagsOptions Soup.parseOptionsFast) t
, bench "tagsoup normal Text" $ nf (Soup.parseTagsOptions Soup.parseOptions) t
, bench "html-parser" $ nf Me.parseTokens t
]
, bgroup "length"
[ bench "tagsoup fast Text" $ whnf (length . Soup.parseTagsOptions Soup.parseOptionsFast) t
, bench "tagsoup normal Text" $ whnf (length . Soup.parseTagsOptions Soup.parseOptions) t
, bench "html-parser" $ whnf (length . Me.parseTokens) t
]
]
instance NFData t => NFData (Soup.Tag t) where
rnf (Soup.TagOpen t attrs) = rnf t `seq` rnf attrs `seq` ()
rnf (Soup.TagClose t) = rnf t `seq` ()
rnf (Soup.TagText t) = rnf t `seq` ()
rnf (Soup.TagComment t) = rnf t `seq` ()
rnf (Soup.TagWarning t) = rnf t `seq` ()
rnf (Soup.TagPosition _ _) = ()