aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authordespresc <christian.j.j.despres@gmail.com>2019-11-04 16:12:37 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2019-11-12 16:03:45 -0800
commit90e436d49604e3fd1ef9432fb23f6d7f6245c7fd (patch)
tree4e7f0692f989643189f1fc6786050d95e239a0ea /benchmark
parentd3966372f5049eea56213b069fc4d70d8af9144c (diff)
downloadpandoc-90e436d49604e3fd1ef9432fb23f6d7f6245c7fd.tar.gz
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/benchmark-pandoc.hs22
-rw-r--r--benchmark/weigh-pandoc.hs7
2 files changed, 16 insertions, 13 deletions
diff --git a/benchmark/benchmark-pandoc.hs b/benchmark/benchmark-pandoc.hs
index 8968cad3e..967728f5d 100644
--- a/benchmark/benchmark-pandoc.hs
+++ b/benchmark/benchmark-pandoc.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TupleSections #-}
{-
Copyright (C) 2012-2019 John MacFarlane <jgm@berkeley.edu>
@@ -24,6 +25,7 @@ import Text.Pandoc.Error (PandocError(..))
import Control.Monad.Except (throwError)
import qualified Text.Pandoc.UTF8 as UTF8
import qualified Data.ByteString as B
+import qualified Data.Text as T
import Criterion.Main
import Criterion.Types (Config(..))
import Data.List (intersect)
@@ -32,12 +34,12 @@ import System.Environment (getArgs)
import qualified Data.ByteString.Lazy as BL
readerBench :: Pandoc
- -> String
+ -> T.Text
-> Maybe Benchmark
readerBench doc name =
case res of
Right (readerFun, inp) ->
- Just $ bench (name ++ " reader")
+ Just $ bench (T.unpack $ name <> " reader")
$ nf (\i -> either (error . show) id $ runPure (readerFun i))
inp
Left _ -> Nothing
@@ -51,7 +53,7 @@ readerBench doc name =
, writerExtensions = wexts } doc
return $ (r def{ readerExtensions = rexts }, inp)
_ -> throwError $ PandocSomeError $ "not a text format: "
- ++ name
+ <> name
getImages :: IO [(FilePath, MimeType, BL.ByteString)]
getImages = do
@@ -61,13 +63,13 @@ getImages = do
,("movie.jpg", "image/jpg", mv)]
writerBench :: Pandoc
- -> String
+ -> T.Text
-> Maybe Benchmark
writerBench doc name =
case res of
Right writerFun ->
Just $ env getImages $ \imgs ->
- bench (name ++ " writer")
+ bench (T.unpack $ name <> " writer")
$ nf (\d -> either (error . show) id $
runPure (do mapM_
(\(fp, mt, bs) ->
@@ -81,11 +83,11 @@ writerBench doc name =
TextWriter w ->
return $ w def{ writerExtensions = wexts }
_ -> throwError $ PandocSomeError
- $ "could not get text writer for " ++ name
+ $ "could not get text writer for " <> name
main :: IO ()
main = do
- args <- filter (\x -> take 1 x /= "-") <$> getArgs
+ args <- filter (\x -> T.take 1 x /= "-") . fmap T.pack <$> getArgs
print args
let matchReader (n, TextReader _) =
null args || ("reader" `elem` args && n `elem` args)
@@ -94,9 +96,9 @@ main = do
null args || ("writer" `elem` args && n `elem` args)
matchWriter _ = False
let matchedReaders = map fst $ (filter matchReader readers
- :: [(String, Reader PandocPure)])
+ :: [(T.Text, Reader PandocPure)])
let matchedWriters = map fst $ (filter matchWriter writers
- :: [(String, Writer PandocPure)])
+ :: [(T.Text, Writer PandocPure)])
inp <- UTF8.toText <$> B.readFile "test/testsuite.txt"
let opts = def
let doc = either (error . show) id $ runPure $ readMarkdown opts inp
diff --git a/benchmark/weigh-pandoc.hs b/benchmark/weigh-pandoc.hs
index f633255df..3b8a414aa 100644
--- a/benchmark/weigh-pandoc.hs
+++ b/benchmark/weigh-pandoc.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Main
Copyright : © 2016-2019 John MacFarlane <jgm@berkeley.edu>
@@ -13,7 +14,7 @@ Benchmarks to determine resource use of readers and writers.
import Prelude
import Weigh
import Text.Pandoc
-import Data.Text (Text)
+import Data.Text (Text, unpack)
main :: IO ()
main = do
@@ -40,12 +41,12 @@ main = do
weighWriter :: Pandoc -> String -> (Pandoc -> Text) -> Weigh ()
weighWriter doc name writer = func (name ++ " writer") writer doc
-weighReader :: Pandoc -> String -> (Text -> Pandoc) -> Weigh ()
+weighReader :: Pandoc -> Text -> (Text -> Pandoc) -> Weigh ()
weighReader doc name reader = do
case lookup name writers of
Just (TextWriter writer) ->
let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
- in func (name ++ " reader") reader inp
+ in func (unpack $ name <> " reader") reader inp
_ -> return () -- no writer for reader