aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-10 23:42:28 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:41 +0100
commit35699ee5339e6a0b865d01246f6553f45551cc78 (patch)
treec1a3f44efa464603ba1dff496c605a483d42edf3 /benchmark
parentb5d15670223ada11a357161f3b057fae6f852554 (diff)
downloadpandoc-35699ee5339e6a0b865d01246f6553f45551cc78.tar.gz
Fixed up weigh-pandoc and benchmark-pandoc so they build.
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/benchmark-pandoc.hs19
-rw-r--r--benchmark/weigh-pandoc.hs8
2 files changed, 15 insertions, 12 deletions
diff --git a/benchmark/benchmark-pandoc.hs b/benchmark/benchmark-pandoc.hs
index e2707de20..ce2e054e7 100644
--- a/benchmark/benchmark-pandoc.hs
+++ b/benchmark/benchmark-pandoc.hs
@@ -22,14 +22,15 @@ import Data.Maybe (mapMaybe)
import Debug.Trace (trace)
readerBench :: Pandoc
- -> (String, ReaderOptions -> String -> IO (Either PandocError Pandoc))
+ -> (String, ReaderOptions -> String -> Pandoc)
-> Maybe Benchmark
readerBench doc (name, reader) =
case lookup name writers of
- Just (PureStringWriter writer) ->
- let inp = writer def{ writerWrapText = WrapAuto} doc
- in return $ bench (name ++ " reader") $ nfIO $
- (fmap handleError <$> reader def{ readerSmart = True }) inp
+ Just (StringWriter writer) ->
+ let inp = either (error . show) id $ runPure
+ $ writer def{ writerWrapText = WrapAuto} doc
+ in return $ bench (name ++ " reader") $ nf
+ (reader def{ readerSmart = True }) inp
_ -> trace ("\nCould not find writer for " ++ name ++ "\n") Nothing
writerBench :: Pandoc
@@ -42,11 +43,13 @@ main :: IO ()
main = do
inp <- readFile "tests/testsuite.txt"
let opts = def{ readerSmart = True }
- let doc = handleError $ readMarkdown opts inp
- let readers' = [(n,r) | (n, StringReader r) <- readers]
+ let doc = either (error . show) id $ runPure $ readMarkdown opts inp
+ let readers' = [(n, \o -> either (error . show) id . runPure . r o)
+ | (n, StringReader r) <- readers]
let readerBs = mapMaybe (readerBench doc)
$ filter (\(n,_) -> n /="haddock") readers'
- let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
+ let writers' = [(n, \o -> either (error . show) id . runPure . w o)
+ | (n, StringWriter w) <- writers]
let writerBs = map (writerBench doc)
$ writers'
defaultMainWith defaultConfig{ timeLimit = 6.0 }
diff --git a/benchmark/weigh-pandoc.hs b/benchmark/weigh-pandoc.hs
index 198d09b46..cf4099721 100644
--- a/benchmark/weigh-pandoc.hs
+++ b/benchmark/weigh-pandoc.hs
@@ -7,7 +7,7 @@ main = do
mainWith $ do
func "Pandoc document" id doc
mapM_
- (\(n,r) -> weighReader doc n (handleError . r def{ readerSmart = True }))
+ (\(n,r) -> weighReader doc n (either (error . show) id . runPure . r def{ readerSmart = True }))
[("markdown", readMarkdown)
,("html", readHtml)
,("docbook", readDocBook)
@@ -15,7 +15,7 @@ main = do
,("commonmark", readCommonMark)
]
mapM_
- (\(n,w) -> weighWriter doc n (w def))
+ (\(n,w) -> weighWriter doc n (either (error . show) id . runPure . w def))
[("markdown", writeMarkdown)
,("html", writeHtmlString)
,("docbook", writeDocbook)
@@ -29,8 +29,8 @@ weighWriter doc name writer = func (name ++ " writer") writer doc
weighReader :: Pandoc -> String -> (String -> Pandoc) -> Weigh ()
weighReader doc name reader = do
case lookup name writers of
- Just (PureStringWriter writer) ->
- let inp = writer def{ writerWrapText = WrapAuto} doc
+ Just (StringWriter writer) ->
+ let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
in func (name ++ " reader") reader inp
_ -> return () -- no writer for reader