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
|
|
|
|
-> (String, ParserState -> String -> Pandoc)
|
|
|
|
-> Benchmark
|
|
|
|
readerBench doc (name, reader) =
|
|
|
|
let writer = case lookup name writers of
|
|
|
|
Just w -> w
|
|
|
|
Nothing -> error $ "Could not find writer for " ++ name
|
|
|
|
inp = writer defaultWriterOptions{ writerWrapText = True
|
|
|
|
, 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 .
|
|
|
|
reader defaultParserState{ stateSmart = True
|
2010-12-11 08:35:31 +01:00
|
|
|
, stateStandalone = True
|
|
|
|
, stateLiterateHaskell =
|
|
|
|
"+lhs" `isSuffixOf` name }) inp
|
|
|
|
|
|
|
|
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
|
2010-12-11 08:35:31 +01:00
|
|
|
(writer defaultWriterOptions{
|
|
|
|
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
|
|
|
|
2010-12-11 08:35:31 +01:00
|
|
|
main = do
|
|
|
|
inp <- readDataFile (Just ".") "README"
|
|
|
|
let ps = defaultParserState{ stateSmart = True }
|
|
|
|
let doc = readMarkdown ps inp
|
|
|
|
let readerBs = map (readerBench doc) readers
|
2010-12-31 00:32:34 +01:00
|
|
|
defaultMain $ map (writerBench doc) writers ++ readerBs ++ normalizeBench doc
|
2010-12-11 08:35:31 +01:00
|
|
|
|