2010-12-10 23:35:31 -08:00
|
|
|
import Text.Pandoc
|
2010-12-25 14:07:26 -08:00
|
|
|
import Text.Pandoc.Shared (readDataFile, normalize)
|
2010-12-10 23:35:31 -08:00
|
|
|
import Criterion.Main
|
|
|
|
import Data.List (isSuffixOf)
|
2010-12-30 15:32:34 -08:00
|
|
|
import Text.JSON.Generic
|
2010-12-10 23:35:31 -08:00
|
|
|
|
|
|
|
readerBench :: Pandoc
|
2012-07-25 22:38:59 -07:00
|
|
|
-> (String, ReaderOptions -> String -> Pandoc)
|
2010-12-10 23:35:31 -08:00
|
|
|
-> Benchmark
|
|
|
|
readerBench doc (name, reader) =
|
|
|
|
let writer = case lookup name writers of
|
2012-07-25 20:08:42 -07:00
|
|
|
Just (PureStringWriter w) -> w
|
|
|
|
_ -> error $ "Could not find writer for " ++ name
|
2012-07-26 22:59:56 -07:00
|
|
|
inp = writer def{ writerWrapText = True
|
2010-12-10 23:35:31 -08: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-22 20:25:15 -08: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-25 22:38:59 -07:00
|
|
|
reader def{ readerSmart = True
|
|
|
|
, readerLiterateHaskell = "+lhs" `isSuffixOf` name
|
2012-07-25 20:20:03 -07:00
|
|
|
}) inp
|
2010-12-10 23:35:31 -08:00
|
|
|
|
|
|
|
writerBench :: Pandoc
|
2010-12-12 23:24:02 -08:00
|
|
|
-> (String, WriterOptions -> Pandoc -> String)
|
2010-12-10 23:35:31 -08:00
|
|
|
-> Benchmark
|
2010-12-12 23:24:02 -08:00
|
|
|
writerBench doc (name, writer) = bench (name ++ " writer") $ nf
|
2012-07-26 22:59:56 -07:00
|
|
|
(writer def{
|
2010-12-10 23:35:31 -08:00
|
|
|
writerWrapText = True
|
|
|
|
, writerLiterateHaskell = "+lhs" `isSuffixOf` name }) doc
|
|
|
|
|
2010-12-30 15:32:34 -08:00
|
|
|
normalizeBench :: Pandoc -> [Benchmark]
|
|
|
|
normalizeBench doc = [ bench "normalize - with" $ nf (encodeJSON . normalize) doc
|
|
|
|
, bench "normalize - without" $ nf encodeJSON doc
|
|
|
|
]
|
2010-12-25 14:07:26 -08:00
|
|
|
|
2012-07-26 10:02:00 -07:00
|
|
|
main :: IO ()
|
2010-12-10 23:35:31 -08:00
|
|
|
main = do
|
|
|
|
inp <- readDataFile (Just ".") "README"
|
2012-07-25 22:38:59 -07:00
|
|
|
let opts = def{ readerSmart = True }
|
|
|
|
let doc = readMarkdown opts inp
|
2010-12-10 23:35:31 -08:00
|
|
|
let readerBs = map (readerBench doc) readers
|
2012-07-25 20:08:42 -07:00
|
|
|
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
|
2012-07-26 09:18:17 -07:00
|
|
|
defaultMain $
|
|
|
|
map (writerBench doc) writers' ++ readerBs ++ normalizeBench doc
|
2010-12-10 23:35:31 -08:00
|
|
|
|