git.iko.soy/typeable/html-parse
on master help sign in
Fix things up
commit31d614da9bc31e0f4142f55ab5d4577e20407c2f authorBen Gamari <ben@smart-cactus.org> dateWed 6 Apr 2016, 01:26 (11 years ago) parent7ebbfc2
3 files changed+46−4
Benchmark.hs+30 Text/HTML/Parser.hs+1−1 html-parse.cabal+15−3
Benchmark.hsnew file+30
@@ -0,0 +1,30 @@
1+import Criterion.Main
2+import qualified Data.Text.IO as TIO
3+import Control.DeepSeq
4+import qualified Text.HTML.TagSoup as Soup
5+import qualified Text.HTML.Parser as Me
6+
7+main :: IO ()
8+main = do
9+ t <- TIO.readFile "test.html"
10+ s <- readFile "test.html"
11+ defaultMain
12+ [ bgroup "Forced"
13+ [ bench "fast parse Text" $ nf (Soup.parseTagsOptions Soup.parseOptionsFast) t
14+ , bench "parse Text" $ nf (Soup.parseTagsOptions Soup.parseOptions) t
15+ , bench "mine Text" $ nf Me.tagStream t
16+ ]
17+ , bgroup "length"
18+ [ bench "fast parse Text" $ whnf (length . Soup.parseTagsOptions Soup.parseOptionsFast) t
19+ , bench "parse Text" $ whnf (length . Soup.parseTagsOptions Soup.parseOptions) t
20+ , bench "mine Text" $ whnf (length . Me.tagStream) t
21+ ]
22+ ]
23+
24+instance NFData t => NFData (Soup.Tag t) where
25+ rnf (Soup.TagOpen t attrs) = rnf t `seq` rnf attrs `seq` ()
26+ rnf (Soup.TagClose t) = rnf t `seq` ()
27+ rnf (Soup.TagText t) = rnf t `seq` ()
28+ rnf (Soup.TagComment t) = rnf t `seq` ()
29+ rnf (Soup.TagWarning t) = rnf t `seq` ()
30+ rnf (Soup.TagPosition _ _) = ()
Text/HTML/Parser.hs+1−1
@@ -1,7 +1,7 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE DeriveGeneric #-}
33
4−module Parser
4+module Text.HTML.Parser
55 ( Token(..)
66 , Attr(..)
77 , token
html-parse.cabal+15−3
@@ -16,8 +16,20 @@ cabal-version: >=1.10
1616library
1717 exposed-modules: Text.HTML.Parser
1818 other-extensions: OverloadedStrings, DeriveGeneric
19− build-depends: base >=4.8 && <4.9
20− deepseq >=1.4 && <1.5
21− attoparsec >=0.13 && <0.14
19+ build-depends: base >=4.8 && <4.9,
20+ deepseq >=1.4 && <1.5,
21+ attoparsec >=0.13 && <0.14,
2222 text >=1.2 && <1.3
2323 default-language: Haskell2010
24+
25+benchmark bench
26+ type: exitcode-stdio-1.0
27+ main-is: Benchmark.hs
28+ other-extensions: OverloadedStrings, DeriveGeneric
29+ build-depends: base >=4.8 && <4.9,
30+ deepseq >=1.4 && <1.5,
31+ attoparsec >=0.13 && <0.14,
32+ text >=1.2 && <1.3,
33+ tagsoup >= 0.13,
34+ criterion >= 1.1
35+ default-language: Haskell2010