2014-05-08 21:50:20 +02:00
|
|
|
{-
|
|
|
|
Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
2010-12-11 08:35:31 +01:00
|
|
|
import Text.Pandoc
|
|
|
|
import Criterion.Main
|
2012-07-27 20:13:18 +02:00
|
|
|
import Criterion.Config
|
|
|
|
import System.Environment (getArgs)
|
|
|
|
import Data.Monoid
|
2010-12-11 08:35:31 +01:00
|
|
|
|
|
|
|
readerBench :: Pandoc
|
2013-01-04 20:11:42 +01:00
|
|
|
-> (String, ReaderOptions -> String -> IO 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-08-09 08:18:19 +02:00
|
|
|
inp = writer def{ writerWrapText = True } 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
|
2013-06-26 03:17:32 +02:00
|
|
|
getLength (Pandoc (Meta _) d) = length d
|
2013-01-04 20:11:42 +01:00
|
|
|
in bench (name ++ " reader") $ whnfIO $ getLength `fmap`
|
|
|
|
(reader def{ readerSmart = True }) 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-08-09 08:18:19 +02:00
|
|
|
(writer def{ writerWrapText = True }) doc
|
2010-12-11 08:35:31 +01:00
|
|
|
|
2012-07-26 19:02:00 +02:00
|
|
|
main :: IO ()
|
2010-12-11 08:35:31 +01:00
|
|
|
main = do
|
2012-07-27 20:13:18 +02:00
|
|
|
args <- getArgs
|
|
|
|
(conf,_) <- parseArgs defaultConfig{ cfgSamples = Last $ Just 20 } defaultOptions args
|
2012-12-30 04:12:19 +01:00
|
|
|
inp <- readFile "README"
|
|
|
|
inp2 <- readFile "tests/testsuite.txt"
|
2012-07-26 07:38:59 +02:00
|
|
|
let opts = def{ readerSmart = True }
|
2012-07-27 20:06:24 +02:00
|
|
|
let doc = readMarkdown opts $ inp ++ unlines (drop 3 $ lines inp2)
|
2013-09-10 18:56:56 +02:00
|
|
|
let readerBs = map (readerBench doc)
|
|
|
|
$ filter (\(n,_) -> n /="haddock") readers
|
2012-07-26 05:08:42 +02:00
|
|
|
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
|
2012-07-27 20:13:18 +02:00
|
|
|
defaultMainWith conf (return ()) $
|
2013-05-09 19:38:11 +02:00
|
|
|
map (writerBench doc) writers' ++ readerBs
|