git.iko.soy/typeable/pandoc
on 1.17.0.3 help sign in
typeable/pandoc/benchmark/benchmark-pandoc.hs
54 lines 2.2 kB history raw
1{-
2Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-}
18import Text.Pandoc
19import Criterion.Main
20import Criterion.Types (Config(..))
21import Data.Maybe (mapMaybe)
22import Debug.Trace (trace)
23import Text.Pandoc.Error
25readerBench :: Pandoc
26 -> (String, ReaderOptions -> String -> IO (Either PandocError Pandoc))
27 -> Maybe Benchmark
28readerBench doc (name, reader) =
29 case lookup name writers of
30 Just (PureStringWriter writer) ->
31 let inp = writer def{ writerWrapText = WrapAuto} doc
32 in return $ bench (name ++ " reader") $ nfIO $
33 (fmap handleError <$> reader def{ readerSmart = True }) inp
34 _ -> trace ("\nCould not find writer for " ++ name ++ "\n") Nothing
36writerBench :: Pandoc
37 -> (String, WriterOptions -> Pandoc -> String)
38 -> Benchmark
39writerBench doc (name, writer) = bench (name ++ " writer") $ nf
40 (writer def{ writerWrapText = WrapAuto }) doc
42main :: IO ()
43main = do
44 inp <- readFile "tests/testsuite.txt"
45 let opts = def{ readerSmart = True }
46 let doc = handleError $ readMarkdown opts inp
47 let readers' = [(n,r) | (n, StringReader r) <- readers]
48 let readerBs = mapMaybe (readerBench doc)
49 $ filter (\(n,_) -> n /="haddock") readers'
50 let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
51 let writerBs = map (writerBench doc)
52 $ writers'
53 defaultMainWith defaultConfig{ timeLimit = 6.0 }
54 (writerBs ++ readerBs)