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
|
2015-10-10 01:01:08 +02:00
|
|
|
import Criterion.Types (Config(..))
|
2014-08-01 13:32:13 +02:00
|
|
|
import Data.Maybe (mapMaybe)
|
|
|
|
import Debug.Trace (trace)
|
2015-02-18 21:10:12 +01:00
|
|
|
import Text.Pandoc.Error
|
2010-12-11 08:35:31 +01:00
|
|
|
|
|
|
|
readerBench :: Pandoc
|
2015-02-18 21:10:12 +01:00
|
|
|
-> (String, ReaderOptions -> String -> IO (Either PandocError Pandoc))
|
2014-08-01 13:32:13 +02:00
|
|
|
-> Maybe Benchmark
|
2015-03-17 06:20:42 +01:00
|
|
|
readerBench doc (name, reader) =
|
|
|
|
case lookup name writers of
|
|
|
|
Just (PureStringWriter writer) ->
|
|
|
|
let inp = writer def{ writerWrapText = True} doc
|
|
|
|
in return $ bench (name ++ " reader") $ nfIO $
|
2015-02-18 21:10:12 +01:00
|
|
|
(fmap handleError <$> reader def{ readerSmart = True }) inp
|
2015-03-30 09:06:40 +02:00
|
|
|
_ -> trace ("\nCould not find writer for " ++ name ++ "\n") Nothing
|
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
|
2014-08-01 22:40:26 +02:00
|
|
|
inp <- readFile "tests/testsuite.txt"
|
2012-07-26 07:38:59 +02:00
|
|
|
let opts = def{ readerSmart = True }
|
2015-02-18 21:10:12 +01:00
|
|
|
let doc = handleError $ readMarkdown opts inp
|
2014-08-01 13:32:13 +02:00
|
|
|
let readers' = [(n,r) | (n, StringReader r) <- readers]
|
|
|
|
let readerBs = mapMaybe (readerBench doc)
|
|
|
|
$ filter (\(n,_) -> n /="haddock") readers'
|
2012-07-26 05:08:42 +02:00
|
|
|
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
|
2014-08-01 13:32:13 +02:00
|
|
|
let writerBs = map (writerBench doc)
|
|
|
|
$ writers'
|
2015-10-10 01:01:08 +02:00
|
|
|
defaultMainWith defaultConfig{ timeLimit = 6.0 }
|
|
|
|
(writerBs ++ readerBs)
|