git.iko.soy/typeable/pandoc
on 2.9 help sign in
typeable/pandoc/benchmark/weigh-pandoc.hs
52 lines 1.6 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{- |
4 Module : Main
5 Copyright : © 2016-2019 John MacFarlane <jgm@berkeley.edu>
6 License : GNU GPL, version 2 or above
8 Maintainer : John MacFarlane <jgm@berkeley.edu>
9 Stability : alpha
10 Portability : portable
12Benchmarks to determine resource use of readers and writers.
13-}
14import Prelude
15import Weigh
16import Text.Pandoc
17import Data.Text (Text, unpack)
19main :: IO ()
20main = do
21 doc <- read <$> readFile "test/testsuite.native"
22 mainWith $ do
23 func "Pandoc document" id doc
24 mapM_
25 (\(n,r) -> weighReader doc n (either (error . show) id . runPure . r def{readerExtensions = pandocExtensions}))
26 [("markdown", readMarkdown)
27 ,("html", readHtml)
28 ,("docbook", readDocBook)
29 ,("latex", readLaTeX)
30 ,("commonmark", readCommonMark)
31 ]
32 mapM_
33 (\(n,w) -> weighWriter doc n (either (error . show) id . runPure . w def))
34 [("markdown", writeMarkdown)
35 ,("html", writeHtml5String)
36 ,("docbook", writeDocbook5)
37 ,("latex", writeLaTeX)
38 ,("commonmark", writeCommonMark)
39 ]
41weighWriter :: Pandoc -> String -> (Pandoc -> Text) -> Weigh ()
42weighWriter doc name writer = func (name ++ " writer") writer doc
44weighReader :: Pandoc -> Text -> (Text -> Pandoc) -> Weigh ()
45weighReader doc name reader = do
46 case lookup name writers of
47 Just (TextWriter writer) ->
48 let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
49 in func (unpack $ name <> " reader") reader inp
50 _ -> return () -- no writer for reader