2010-12-11 08:35:31 +01:00
|
|
|
import Text.Pandoc
|
2010-12-25 23:07:26 +01:00
|
|
|
import Text.Pandoc.Shared (readDataFile, normalize)
|
2010-12-11 08:35:31 +01:00
|
|
|
import Criterion.Main
|
|
|
|
import Data.List (isSuffixOf)
|
2010-12-31 00:32:34 +01:00
|
|
|
import Text.JSON.Generic
|
2010-12-11 08:35:31 +01:00
|
|
|
|
|
|
|
readerBench :: Pandoc
|
2012-07-26 07:38:59 +02:00
|
|
|
-> (String, ReaderOptions -> String -> Pandoc)
|
2010-12-11 08:35:31 +01:00
|
|
|
-> Benchmark
|
|
|
|
readerBench doc (name, reader) =
|
|
|
|
let writer = case lookup name writers of
|
2012-07-26 05:08:42 +02:00
|
|
|
Just (PureStringWriter w) -> w
|
|
|
|
_ -> error $ "Could not find writer for " ++ name
|
2012-07-27 07:59:56 +02:00
|
|
|
inp = writer def{ writerWrapText = True
|
2010-12-11 08:35:31 +01:00
|
|
|
, writerLiterateHaskell =
|
|
|
|
"+lhs" `isSuffixOf` name } doc
|
New HTML reader using tagsoup as a lexer.
* The new reader is faster and more accurate.
* API changes for Text.Pandoc.Readers.HTML:
- removed rawHtmlBlock, anyHtmlBlockTag, anyHtmlInlineTag,
anyHtmlTag, anyHtmlEndTag, htmlEndTag, extractTagType,
htmlBlockElement, htmlComment
- added htmlTag, htmlInBalanced, isInlineTag, isBlockTag, isTextTag
* tagsoup is a new dependency.
* Text.Pandoc.Parsing: Generalized type on readWith.
* Benchmark.hs: Added length calculation to force full evaluation.
* Updated HTML reader tests.
* Updated markdown and textile readers to use the functions from
the HTML reader.
* Note: The markdown reader now correctly handles some cases it did not
before. For example:
<hr/>
is reproduced without adding a space.
<script>
a = '<b>';
</script>
is parsed correctly.
2010-12-23 05:25:15 +01:00
|
|
|
-- we compute the length to force full evaluation
|
|
|
|
getLength (Pandoc (Meta a b c) d) =
|
|
|
|
length a + length b + length c + length d
|
|
|
|
in bench (name ++ " reader") $ whnf (getLength .
|
2012-07-26 07:38:59 +02:00
|
|
|
reader def{ readerSmart = True
|
|
|
|
, readerLiterateHaskell = "+lhs" `isSuffixOf` name
|
2012-07-26 05:20:03 +02:00
|
|
|
}) inp
|
2010-12-11 08:35:31 +01:00
|
|
|
|
|
|
|
writerBench :: Pandoc
|
2010-12-13 08:24:02 +01:00
|
|
|
-> (String, WriterOptions -> Pandoc -> String)
|
2010-12-11 08:35:31 +01:00
|
|
|
-> Benchmark
|
2010-12-13 08:24:02 +01:00
|
|
|
writerBench doc (name, writer) = bench (name ++ " writer") $ nf
|
2012-07-27 07:59:56 +02:00
|
|
|
(writer def{
|
2010-12-11 08:35:31 +01:00
|
|
|
writerWrapText = True
|
|
|
|
, writerLiterateHaskell = "+lhs" `isSuffixOf` name }) doc
|
|
|
|
|
2010-12-31 00:32:34 +01:00
|
|
|
normalizeBench :: Pandoc -> [Benchmark]
|
|
|
|
normalizeBench doc = [ bench "normalize - with" $ nf (encodeJSON . normalize) doc
|
|
|
|
, bench "normalize - without" $ nf encodeJSON doc
|
|
|
|
]
|
2010-12-25 23:07:26 +01:00
|
|
|
|
2012-07-26 19:02:00 +02:00
|
|
|
main :: IO ()
|
2010-12-11 08:35:31 +01:00
|
|
|
main = do
|
|
|
|
inp <- readDataFile (Just ".") "README"
|
2012-07-26 07:38:59 +02:00
|
|
|
let opts = def{ readerSmart = True }
|
|
|
|
let doc = readMarkdown opts inp
|
2010-12-11 08:35:31 +01:00
|
|
|
let readerBs = map (readerBench doc) readers
|
2012-07-26 05:08:42 +02:00
|
|
|
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
|
2012-07-26 18:18:17 +02:00
|
|
|
defaultMain $
|
|
|
|
map (writerBench doc) writers' ++ readerBs ++ normalizeBench doc
|
2010-12-11 08:35:31 +01:00
|
|
|
|