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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE StandaloneDeriving, DeriveGeneric #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Benchmark speed.
module Main where
import Control.DeepSeq
import Criterion
import Criterion.Main
import Data.ByteString (ByteString)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import GHC.Generics
import qualified Text.XML.Expat.SAX as Hexpat
import qualified Text.XML.Expat.Tree as HexpatTree
import qualified Text.XML.Hexml as Hexml
import Text.XML.Light as XML
import qualified Xeno.SAX
import qualified Xeno.Types
import qualified Xeno.DOM
import qualified Xeno.DOM.Robust
#ifdef LIBXML2
import qualified Text.XML.LibXML.Parser as Libxml2
#endif
readFileZ :: FilePath -> IO (ByteString, Xeno.Types.ByteStringZeroTerminated)
readFileZ fn = do
!s <- S.readFile fn
let !sz = Xeno.Types.BSZT (s `S.snoc` 0)
return (s, sz)
main :: IO ()
main = defaultMain $
(flip map) [ ("4KB", "data/books-4kb.xml")
, ("31KB", "data/text-31kb.xml")
, ("211KB", "data/fabricated-211kb.xml")
]
$ \(group, fn) ->
env (readFileZ fn)
(\ ~(!input, !inputz) -> bgroup group
[ bench "hexml-dom" (whnf Hexml.parse input)
, bench "xeno-sax" (whnf Xeno.SAX.validate input)
, bench "xeno-sax-z" (whnf Xeno.SAX.validate inputz)
, bench "xeno-sax-ex" (whnf Xeno.SAX.validateEx input)
, bench "xeno-sax-ex-z" (whnf Xeno.SAX.validateEx inputz)
, bench "xeno-dom" (whnf Xeno.DOM.parse input)
, bench "xeno-dom-with-recovery" (whnf Xeno.DOM.Robust.parse input)
, bench
"hexpat-sax"
(whnf
((Hexpat.parseThrowing Hexpat.defaultParseOptions :: L.ByteString -> [Hexpat.SAXEvent ByteString ByteString]) .
L.fromStrict)
input)
, bench
"hexpat-dom"
(whnf
((HexpatTree.parse' HexpatTree.defaultParseOptions :: ByteString -> Either HexpatTree.XMLParseError (HexpatTree.Node ByteString ByteString)))
input)
, bench "xml-dom" (nf XML.parseXMLDoc input)
#ifdef LIBXML2
, bench "libxml2-dom" (whnfIO (Libxml2.parseMemory input))
#endif
])
deriving instance Generic Content
deriving instance Generic Element
deriving instance Generic CData
deriving instance Generic CDataKind
deriving instance Generic QName
deriving instance Generic Attr
instance NFData Content
instance NFData Element
instance NFData CData
instance NFData CDataKind
instance NFData QName
instance NFData Attr
|